本文介绍了通知没有触发一段时间(FLutter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..如何使用 flutter_local_notification pacakage 触发特定时间段的通知.我在 pub.dev 上尝试了教程,但我仍然无法做到.有人请帮忙.
How do I trigger a notification for a particular time period using flutter_local_notification pacakage. I tried out the tutorial on pub.dev but I am still not able to do it. Someone, please help.
这是我在下午 4:23 触发它的尝试.
Here is my try to trigger it at 4:23 pm.
tz.TZDateTime _nextInstanceOfTenAM() {
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
tz.TZDateTime scheduledDate =
tz.TZDateTime(tz.local, now.year, now.month, now.day, 16, 23));
if (scheduledDate.isBefore(now)) {
scheduledDate = scheduledDate.add(const Duration(days: 1));
}
return scheduledDate;
Future<void> displayNotification() async {
notificationsPlugin.zonedSchedule(
0,
"Wake Up",
'Time to wake up now',
_nextInstanceOfTenAM(),
//tz.TZDateTime.now(tz.local).add(Duration(seconds: 3)),
NotificationDetails(
android: AndroidNotificationDetails(
'channel id', 'channel name', 'channel description'),
),
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
androidAllowWhileIdle: true);
}
推荐答案
必须在flutter中注册一个后台服务.请通过以下链接-
You have to register a background service in flutter. Please go though following links-
https://flutter.dev/docs/resources/faq#can-i-run-dart-code-in-the-background-of-an-flutter-app
如何创建Flutter 后台服务,在应用关闭时也能运行
这篇关于通知没有触发一段时间(FLutter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论