是否有任何方法可以使用flutter本地通知同时安排多个通知



我使用flutter本地通知包在我的应用程序中安排通知但是它一次只安排一个通知,如果我在不同的时间设置两个通知,那么只显示一个通知下面是我的定时通知功能代码:

Future<void> _configureLocalTimeZone() async {
tz.initializeTimeZones();
final String timeZone = await FlutterNativeTimezone.getLocalTimezone();
tz.setLocalLocation(tz.getLocation(timeZone));
}
/// Set right date and time for notifications
tz.TZDateTime _convertTime(int hour, int minutes) {
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
tz.TZDateTime scheduletime = tz.TZDateTime(
tz.local,
now.year,
now.month,
now.day,
hour,
minutes,
);
if (scheduletime.isBefore(now)) {
scheduletime = scheduletime.add(const Duration(days: 1));
}
print(scheduletime);
return scheduletime;
}
Future scheduled_notification() async{
AndroidNotificationDetails android_notification=AndroidNotificationDetails('your channel id', 'Your channel name',
channelDescription: 'your channel description',
playSound: true,
priority: Priority.high,
importance: Importance.max,
);
NotificationDetails notificationDetails=NotificationDetails(android: android_notification);
await flutterLocalNotificationsPlugin.zonedSchedule(
0 ,
'Dose',
'Ayesha apky puff ka time hogya hai...',
_convertTime(hours_24,minutes) ,
notificationDetails,
uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
androidAllowWhileIdle: true
);
}

这里是我调用函数的地方:

ElevatedButton(
onPressed:  (){
scheduled_notification();
}
)

对于要同时安排的通知,您需要提及每个通知的id,在您的情况下,您的notificationId=0,如果您使用此id安排超过1个通知,则前一个通知将被新通知覆盖。

await flutterLocalNotificationsPlugin.zonedSchedule(
0 ,
'Dose',
'Ayesha apky puff ka time hogya hai...',
_convertTime(hours_24,minutes) ,
notificationDetails,
uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
androidAllowWhileIdle: true
);

await flutterLocalNotificationsPlugin.zonedSchedule(
1 ,
'Dose',
'Ayesha apky puff ka time hogya hai...',
_convertTime(hours_24,minutes) ,
notificationDetails,
uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
androidAllowWhileIdle: true
);

相关内容

  • 没有找到相关文章

最新更新