通知没有触发一段时间(FLutter)

编程入门 行业动态 更新时间:2024-10-23 09:22:15
本文介绍了通知没有触发一段时间(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:关键词]

本文发布于:2023-04-30 12:21:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393562.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   FLutter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!