Flutter - Dynamic Notifications Reschedule

27 views Asked by At

I am using Awesome Notifications to schedule my Flutter app notifications, and I was wondering if it's possible to dynamically reschedule notifications using the "onNotificationDisplayedMethod" method

I have tried to call my scheduleNextNotificationwith the onNotificationDisplayedMethod method, only the first scheduled notification is firing, when the next notification is due, it's not rescheduling.

My actual _nextDate is dynamic and random, not 5 minutes interval that's why I am trying to dynamically reschedule the notifications.

static Future <void> scheduleNextNotification(Map<String, dynamic> _jsonData) async{
    print('scheduleNextNotification triggered');
    DateTime _nextDate = DateTime.now().add(Duration(minutes:5));

          AwesomeNotifications().createNotification(
            content: NotificationContent(
                id: 0,
                channelKey: 'default_channel',
                title: 'It\'s Time',
                body: 'Get Ready',
                payload:  payload
            ),
            schedule: NotificationCalendar.fromDate(
              date: _nextDate ,
              preciseAlarm: true,
              allowWhileIdle: true,
            ),
          );
}

  /// Use this method to detect every time that a new notification is displayed
  @pragma("vm:entry-point")
  static Future <void> onNotificationDisplayedMethod(ReceivedNotification receivedNotification) async {
    print(DateTime.now());
    Map<String, dynamic>? _payload = receivedNotification.payload?.cast<String, dynamic>();
    await scheduleNextNotification(_payload!);

  }
0

There are 0 answers