0

How do I trigger a notification for a particular time period using flutter_local_notification pacakage. I tried out the tutorial on pub.dev but I am still not able to do it. Someone, please help.

Here is my try to trigger it at 4:23 pm.

  tz.TZDateTime _nextInstanceOfTenAM() {
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
tz.TZDateTime scheduledDate =
tz.TZDateTime(tz.local, now.year, now.month, now.day, 16, 23));
if (scheduledDate.isBefore(now)) {
  scheduledDate = scheduledDate.add(const Duration(days: 1));
}
return scheduledDate;



Future<void> displayNotification() async {
notificationsPlugin.zonedSchedule(
    0,
    "Wake Up",
    'Time to wake up now',
    _nextInstanceOfTenAM(),
    //tz.TZDateTime.now(tz.local).add(Duration(seconds: 3)),
    NotificationDetails(
      android: AndroidNotificationDetails(
          'channel id', 'channel name', 'channel description'),
    ),
    uiLocalNotificationDateInterpretation:
    UILocalNotificationDateInterpretation.absoluteTime,
    androidAllowWhileIdle: true);

}

1 Answers1

0

You have to register a background service in flutter. Please go though following links-

https://flutter.dev/docs/resources/faq#can-i-run-dart-code-in-the-background-of-an-flutter-app

How to create a Flutter background service that works also when app closed