【问题标题】:is there any way to schedule multiple notifications at same time using flutter local notification有没有办法使用颤振本地通知同时安排多个通知
【发布时间】:2022-06-26 02:09:07
【问题描述】:

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

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();
}
)

【问题讨论】:

    标签: flutter dart timezone localnotification flutter-notification


    【解决方案1】:

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

    等待颤振LocalNotificationsPlugin.zonedSchedule( 0 , '剂量', 'Ayesha apky puff ka time hogya hai...', _convertTime(hours_24,minutes) , 通知详情, uiLocalNotificationDateInterpretation:UILocalNotificationDateInterpretation.absoluteTime, matchDateTimeComponents: DateTimeComponents.time, androidAllowWhileIdle: 真 );

    等待颤振LocalNotificationsPlugin.zonedSchedule( 1、 '剂量', 'Ayesha apky puff ka time hogya hai...', _convertTime(hours_24,minutes) , 通知详情, uiLocalNotificationDateInterpretation:UILocalNotificationDateInterpretation.absoluteTime, matchDateTimeComponents: DateTimeComponents.time, androidAllowWhileIdle: 真 );

    【讨论】:

      猜你喜欢
      • 2019-02-26
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 2012-04-07
      • 2020-11-28
      • 2021-10-12
      • 1970-01-01
      相关资源
      最近更新 更多