scheduleNotification method

Future<void> scheduleNotification(
  1. int id,
  2. String title,
  3. String body,
  4. DateTime scheduledTime,
  5. String? payload,
)

Implementation

Future<void> scheduleNotification(
    int id, String title, String body, DateTime scheduledTime, String? payload) async {
  const AndroidNotificationDetails androidNotificationDetails =
  AndroidNotificationDetails(
    'your_scheduled_channel_id',
    'your_scheduled_channel_name',
    channelDescription: 'your_scheduled_channel_description',
    importance: Importance.max,
    priority: Priority.high,
  );

  const NotificationDetails notificationDetails = NotificationDetails(
      android: androidNotificationDetails,
      iOS: DarwinNotificationDetails());

  if (await getNotificationStatus()) { // Use the private method
    await flutterLocalNotificationsPlugin.zonedSchedule(
        id,
        title,
        body,
        tz.TZDateTime.from(scheduledTime, tz.getLocation('your_timezone')),
        notificationDetails,
        uiLocalNotificationDateInterpretation:
        UILocalNotificationDateInterpretation.absoluteTime,
        payload: payload,
        androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle);
  } else {
    AppLogs.showErrorLogs('Notification not scheduled');
  }
}