scheduleNotification method

Future<void> scheduleNotification({
  1. required int hour,
  2. required int minute,
  3. required int id,
  4. required String title,
  5. required String body,
  6. required String payload,
})

Implementation

Future<void> scheduleNotification(
    {required int hour,
    required int minute,
    required int id,
    required String title,
    required String body,
    required String payload}) async {
  final platformChannelSpecifics = await _notificationDetails();
  tz.TZDateTime scheduledDate = _nextInstanceOfTime(hour, minute);
  if (kDebugMode) {
    print(scheduledDate);
  }
  await _localNotifications.zonedSchedule(
      id, title, body, scheduledDate, platformChannelSpecifics,
      uiLocalNotificationDateInterpretation:
          UILocalNotificationDateInterpretation.absoluteTime,
      androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle);
  List<ActiveNotification> activeNotifications =
      await _localNotifications.getActiveNotifications();
  if (kDebugMode) {
    print('active notifications:');
    for (ActiveNotification notification in activeNotifications) {
      print(notification.body);
    }
  }
  List<PendingNotificationRequest> requests =
      await _localNotifications.pendingNotificationRequests();
  if (kDebugMode) {
    print('pending requests:');
  }
  for (PendingNotificationRequest request in requests) {
    if (kDebugMode) {
      print(request.title);
    }
  }
}