[英]showing notifications using flutter
I use the flutter local notifications plugin but I don't know how to schedule notifications using flutterLocalNotificationsPlugin.zonedSchedule.我使用 flutter 本地通知插件,但我不知道如何使用 flutterLocalNotificationsPlugin.zonedSchedule 安排通知。 noted that I can't use flutterLocalNotificationsPlugin.showDailyAtTime because it's deprecated注意到我不能使用 flutterLocalNotificationsPlugin.showDailyAtTime 因为它已被弃用
Instead of this :而不是这个:
await flutterLocalNotificationsPlugin.showDailyAtTime(
0, 'Title', 'Body', time, platformChannel,
payload: 'New payload');
You can use this :你可以使用这个:
var dateTime = DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 18, 2, 0);
await flutterLocalNotificationsPlugin.zonedSchedule(
0,
'scheduled title',
'scheduled body',
tz.TZDateTime.from(dateTime, tz.local),
platformChannel,
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
);
I didn't test it, but this should repeat every day at 18:02.我没有测试它,但这应该在每天 18:02 重复。 Remember to add this package:记得添加这个包:
import 'package:timezone/data/latest.dart' as tz;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.