如何使用 dart-flutter 每天重复本地通知?以及如何将“2:00 AM”时间格式解析为 TimeZone?

问题描述

我正在尝试对患者的用药时间进行每日剩余,我正在使用 Flutter_local_notifications 并且效果很好。 这是我的功能,我想让它每天重复,

void scheduleAlarm() async {
      var androidplatformChannelSpecifics = AndroidNotificationDetails(
        'alarm_notif','alarm_notif','Channel for Alarm notification',icon: 'codex_logo',sound: RawResourceAndroidNotificationSound('notification_sound'),largeIcon: DrawableResourceAndroidBitmap('drug'),);
      tz.initializeTimeZones();
      tz.setLocalLocation(tz.getLocation('America/Detroit'));
      var iOSPlatformChannelSpecifics = IOSNotificationDetails(
          sound: 'notification_sound.wav',presentAlert: true,presentBadge: true,presentSound: true);
      var platformChannelSpecifics = NotificationDetails(
          android: androidplatformChannelSpecifics,iOS: iOSPlatformChannelSpecifics);
      await FlutterlocalnotificationsPlugin.zonedSchedule(
        0,'Panadol','Don\'t forget to take your medicine 2:00 AM',tz.TZDateTime.Now(tz.local).add(Duration(seconds: 5)),platformChannelSpecifics,androidAllowWhileIdle: true,);
    }

并且我想更改此行,以便我可以以这种格式传递从 TimePicker 获得的时间字符串 '2:00 AM'

tz.TZDateTime.Now(tz.local).add(Duration(seconds: 5)),

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)