MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.47k stars 1.4k forks source link

Need help with zonedSchedule #2240

Closed archsolar closed 5 months ago

archsolar commented 9 months ago

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 commented 9 months ago

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);
  }
Artemniy commented 8 months ago

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));
plammens commented 8 months ago

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 commented 8 months ago

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

MaikuB commented 5 months ago

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

archsolar commented 5 months ago

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