我正在try 实现本地通知,在我升级应用程序版本之前,它工作得很好,如下所示:

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

  showNotification() async {
   var android = AndroidNotificationDetails(
        'channel id', 'channel name');
    var iOS = DarwinNotificationDetails();
    var platform = NotificationDetails(android: android, iOS: iOS);
    await flutterLocalNotificationsPlugin.periodicallyShow(0, 'Hello user,',
        "Don't miss out on the exciting deals for the day.", RepeatInterval.everyMinute, platform);
   
  }

但自从我更改为flutter_local_notifications: ^10.0.0后,我就再也没有收到任何通知了.虽然我收到了错误消息[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: NoSuchMethodError: The method 'periodicallyShow' was called on null.Tried calling: periodicallyShow(0, "Hello Hobber,", "Don't miss out on the exciting deals for the day.", Instance of 'RepeatInterval', Instance of 'NotificationDetails'),但有人能帮助我吗?

推荐答案

按如下方式初始化FlutterLocalNotificationsPlugin对象:

FlutterLocalNotificationsPlugin fltterLocalNotificationsPlugin=FlutterLocalNotificationsPlugin()

Flutter相关问答推荐

创建多个具有适当填充和对齐的按钮的最佳方法

飘动的文本用/字符绕转

Flutter 蜂窝单元测试

查询满足AND条件的文档的FiRestore

Flutter :在后台实现振动

来自FirebaseAuth的错误DisplayName和邮箱在Flutter应用程序中给出错误

如何翻转这种剪刀设计

如何处理平台游戏的对象冲突?

如何在 Flutter 中设计像 zomato 应用程序一样的搜索字段?

Flutter中有没有办法区分鼠标左右平移?

Flutter http 请求获取 null

在 Flutter 中从 FireStore 获取数据并编译它们需要太多时间

创建混合 TextWidget 和 TextFieldWidget

在 Flutter 中读取 Firebase 数据库数据时遇到问题

我可以定义一次 sharedPreferences 并在需要数据显示到 flutter 应用程序时调用它吗?

Flutter 构建方法使用的是旧版本的变量?

在 Flame Forge2d 中射击子弹

gridview 的所有按钮都应该在Flutter 中适合其父容器

使用 mocktail 包进行单元测试时,类型Null不是Future类型的子类型

Flutter ListView builder 未使用新数据更新