I want to receive three notifications at different times using the same notification ID. However, I have been able to send only one notification and couldn't manage to send the other two notifications.
packages
flutter_local_notifications: ^13.0.0
pass data to function code
// Generate a random notification ID
final notificationID = Random().nextInt(10000);
NotificationService().scheduleNotification(id:notificationID ,title: 'Scheduled Notification1 ${widget.petName} ', body: '$nextDate $notificationID ${title.text}',
scheduledNotificationDateTime: DateTime.parse('2023-05-18 16:46:00.000'),scheduledNotificationDateTime2: DateTime.parse('2023-05-18 16:48:00.000'),scheduledNotificationDateTime3: DateTime.parse('2023-05-18 16:49:00.000'));
NotificationService() class
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:timezone/timezone.dart' as tz;
class NotificationService {
final FlutterLocalNotificationsPlugin notificationsPlugin =
FlutterLocalNotificationsPlugin();
Future<void> initNotification() async {
AndroidInitializationSettings initializationSettingsAndroid =
const AndroidInitializationSettings('mipmap/ic_launcher');
var initializationSettingsIOS = DarwinInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
onDidReceiveLocalNotification:
(int id, String? title, String? body, String? payload) async {});
var initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
await notificationsPlugin.initialize(initializationSettings,
onDidReceiveNotificationResponse:
(NotificationResponse notificationResponse) async {});
}
notificationDetails() {
return const NotificationDetails(
android: AndroidNotificationDetails('channelId', 'channelName',
importance: Importance.max),
iOS: DarwinNotificationDetails());
}
Future showNotification(
{required int id, String? title, String? body, String? payLoad}) async {
return notificationsPlugin.show(
id, title, body, await notificationDetails());
}
Future scheduleNotification(
{required int id,
String? title,
String? body,
String? payLoad,
required DateTime scheduledNotificationDateTime, required DateTime scheduledNotificationDateTime2, required DateTime scheduledNotificationDateTime3}) async {
print(" scheduledNotificationDateTime $scheduledNotificationDateTime");
print(" body $body");
print(" title $title");
print(" id $id");
return notificationsPlugin.zonedSchedule(
id,
title,
body,
tz.TZDateTime.from(
scheduledNotificationDateTime,
tz.local,
),
await notificationDetails(),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
}
}
void main
How solve this and receive three notifications at different times using the same notification ID ?
