0

我已经使用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);
4

0 回答 0