flutter - Flutter - 在颤动中更改时区后未触发本地通知
问题描述
我已经使用flutter_local_notifications 5.0.0包设置了本地通知。所有通知都在当前时区正常工作。但是如果我从印度旅行到美国,我的时区就会改变。结果,我在美国时没有收到任何通知。我从早上 9 点到晚上 9 点每 30 分钟设置一次通知。谁能帮我解决这个问题?
我的代码如下:
DateTime now = new DateTime.now();
DateTime dateTime = DateTime(now.year, now.month, now.day, time.hour, time.minute);
final timeZone = TimeZoneClass();
// The device's timezone.
String timeZoneName = await timeZone.getTimeZoneName();
// Find the 'current location'
final location = await timeZone.getLocation(timeZoneName);
final scheduledDate = tz.TZDateTime.from(dateTime, location);
var iosChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
android: androidChannelSpecifics, iOS: iosChannelSpecifics);
await flutterLocalNotificationsPlugin.zonedSchedule(id, APP_NAME, body, scheduledDate, platformChannelSpecifics,
matchDateTimeComponents: DateTimeComponents.time,
payload: payLoad,
uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
androidAllowWhileIdle: true);
解决方案
推荐阅读
- git - git ls-files 排除目录中的文件
- python - 有什么方法可以从 CSV 文件中解析正确的日期行吗?
- c# - 如何将单独的参数传递给 Xamarin Android C# 中的 ListView.ItemClick 调用
- c - 以太网 CRC 计算
- r - R - 使用列表中每个项目的第一个元素过滤列表
- c++ - 产生一个线程本身是否提供内存顺序保证?
- python - 如何用 2 列中的 pandas 计算频率并在 matplotlib 中绘制 3d 图
- ruby-on-rails - Rspec:如何测试引发错误的方法
- python - python请求:将“referer”标头添加到重定向请求
- amazon-web-services - 每天将批处理文件从 Linux EC2 实例自动传输到 Windows EC2 实例