如何解决使用时间戳的 Flutter 本地通知
我正在尝试通过时间戳安排通知。 我正在使用 flutter_local_notifications 进行本地通知。
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
void showNotification() async {
// converting timestamp to DateTime
var date = DateTime.fromMillisecondsSinceEpoch(1615463999 * 1000);
print(date); // 2021-03-11 17:29:59.000 (My Local time when the notification is to be shown)
final String currentTimeZone =
await FlutterNativeTimezone.getLocalTimezone();
final location = tz.getLocation(currentTimeZone);
// print(currentTimeZone); // Asia/Kolkata
// print(location); // Asia/Kolkata (It also provides same output)
//converting DateTime to TimeZone format(as per doc of local notification)
var time2 = tz.TZDateTime.from(date,location);
print(time2); //2021-03-11 17:29:59.000+0530
var android = AndroidNotificationDetails(
'id','channel ','description',priority: Priority.high,importance: Importance.max,playSound: true,);
var iOS = IOSNotificationDetails();
final NotificationDetails platform =
NotificationDetails(android: android,iOS: iOS);
await flutterLocalNotificationsPlugin.zonedSchedule(0,'Flutter devs','Flutter Local Notification Demo',time2,platform,androidAllowWhileIdle: true,uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
}
通知永远不会出现。有人可以指出我做错了什么吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。