flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

Need help with zonedSchedule

Open archsolar opened this issue 1 year ago • 4 comments

This code works perfectly on my android app.

    await flutterLocalNotificationsPlugin.show(
      id, 'Task Reminder', 'Time to finish a task!',
      platformChannelSpecifics,
      payload: 'todo payload',
    );

This code however, doesn't do anything, I tried a lot of things, but I can't figure out what it might be.

    await flutterLocalNotificationsPlugin.zonedSchedule(
      id, 'Task Reminder', 'Time to finish a task!',
      // Notification in 5 seconds.
      tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
      platformChannelSpecifics,
      uiLocalNotificationDateInterpretation:
          UILocalNotificationDateInterpretation.absoluteTime,
      androidScheduleMode: AndroidScheduleMode
          .alarmClock, // Ensure the notification is shown even if the phone is in a low-power idle mode
      matchDateTimeComponents: DateTimeComponents
          .time, // Match on time component only for daily recurrence
      payload: 'todo payload',
    );

archsolar avatar Feb 11 '24 23:02 archsolar

This also does not display.

  static Future<void> _zonedScheduleAlarmClockNotification() async {
    await flutterLocalNotificationsPlugin.zonedSchedule(
        123,
        'scheduled alarm clock title',
        'scheduled alarm clock body',
        tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
        const NotificationDetails(
            android: AndroidNotificationDetails(
                'alarm_clock_channel', 'Alarm Clock Channel',
                channelDescription: 'Alarm Clock Notification')),
        androidScheduleMode: AndroidScheduleMode.alarmClock,
        uiLocalNotificationDateInterpretation:
            UILocalNotificationDateInterpretation.absoluteTime);
  }

archsolar avatar Feb 11 '24 23:02 archsolar

Did you check what the time tz.TZDateTime.now(tz.local) gives? I had this problem when my tz was not properly initialised, so before calling tz.local I had to make this:

  tz.initializeTimeZones();
  final String timeZoneName = await FlutterTimezone.getLocalTimezone();
  tz.setLocalLocation(tz.getLocation(timeZoneName));

Artemniy avatar Feb 19 '24 16:02 Artemniy

I'm experiencing the same issue after updating to version 16.3.2 from version 13.0.0. I have checked that my timezone is set correctly. I also tried changing between absoluteTime and wallClockTime.

plammens avatar Feb 20 '24 22:02 plammens

Found the culprit: from version 16.0.0, the plugin only specifies the bare minimum in AndroidManifest.xml, the rest has to be done by hand. This includes enabling scheduled notifications.

See the README: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications#androidmanifestxml-setup

plammens avatar Feb 20 '24 22:02 plammens

Closing this as the OP didn't respond to others who offered help

MaikuB avatar Jun 10 '24 06:06 MaikuB

Thank you all for helping out! Sorry for being unresponsive.

archsolar avatar Jun 11 '24 03:06 archsolar