android – Flutter Schedule Reminder

Spread the love


I’ve a reasonably easy subject concerning reminder scheduling in flutter. I’m simply making an attempt to set a fundamental reminder for one minute sooner or later (as a take a look at, it could possibly be 3 days sooner or later, 2 hours, and many others…). I’ve 2 code snippets under, one which works and one that doesn’t. The one distinction is how I set the TZDateTime. I’m very confused.

Why is that this code not working

var now = tz.TZDateTime.now(tz.native);
tz.TZDateTime scheduledDate = tz.TZDateTime(
    tz.native,
    now.yr,
    now.month,
    now.day,
    22,
    47);
await flutterLocalNotificationsPlugin
    .zonedSchedule(
  1,
  'scheduled title',
  'scheduled physique',
  scheduledDate,
  NotificationDetails(
    android: AndroidNotificationDetails(
        'you_can_name_it_whatever',
        'your channel title',
        channelDescription:
            'your channel description',
        significance: Significance.max,
        precedence: Precedence.max),
  ),
  androidScheduleMode:
      AndroidScheduleMode.exactAllowWhileIdle,
  uiLocalNotificationDateInterpretation:
      UILocalNotificationDateInterpretation
          .absoluteTime,
  matchDateTimeComponents:
      DateTimeComponents.dayOfWeekAndTime,
);
} else {
flutterLocalNotificationsPlugin.cancel(1);
}
await flutterLocalNotificationsPlugin
    .zonedSchedule(
  1,
  'scheduled title',
  'scheduled physique',
  scheduledDate,
  const NotificationDetails(
    android: AndroidNotificationDetails(
        'you_can_name_it_whatever',
        'your channel title',
        channelDescription:
            'your channel description',
        significance: Significance.max,
        precedence: Precedence.max),
  ),
  androidScheduleMode:
      AndroidScheduleMode.exactAllowWhileIdle,
  uiLocalNotificationDateInterpretation:
      UILocalNotificationDateInterpretation
          .absoluteTime,
  matchDateTimeComponents:
      DateTimeComponents.dayOfWeekAndTime,
);

However this code is

await flutterLocalNotificationsPlugin
    .zonedSchedule(
  1,
  'scheduled title',
  'scheduled physique',
  scheduledDate,
  NotificationDetails(
    android: AndroidNotificationDetails(
        'you_can_name_it_whatever',
        'your channel title',
        channelDescription:
            'your channel description',
        significance: Significance.max,
        precedence: Precedence.max),
  ),
  androidScheduleMode:
      AndroidScheduleMode.exactAllowWhileIdle,
  uiLocalNotificationDateInterpretation:
      UILocalNotificationDateInterpretation
          .absoluteTime,
  matchDateTimeComponents:
      DateTimeComponents.dayOfWeekAndTime,
);
} else {
flutterLocalNotificationsPlugin.cancel(1);
}
await flutterLocalNotificationsPlugin
    .zonedSchedule(
  1,
  'scheduled title',
  'scheduled physique',
  tz.TZDateTime.now(tz.native).add(Period(
seconds: 1)),
  const NotificationDetails(
    android: AndroidNotificationDetails(
        'you_can_name_it_whatever',
        'your channel title',
        channelDescription:
            'your channel description',
        significance: Significance.max,
        precedence: Precedence.max),
  ),
  androidScheduleMode:
      AndroidScheduleMode.exactAllowWhileIdle,
  uiLocalNotificationDateInterpretation:
      UILocalNotificationDateInterpretation
          .absoluteTime,
  matchDateTimeComponents:
      DateTimeComponents.dayOfWeekAndTime,
);

Leave a Reply

Your email address will not be published. Required fields are marked *