我的Flutter本地通知存在一些错误 [英] There's some error on my Flutter Local Notification

查看:69
本文介绍了我的Flutter本地通知存在一些错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助,致电本地通知时出错.

I need help, there's an error when calling Local Notification.

对于initState:

For the initState :

initState() {
    super.initState();
    flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
    // initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
    var initializationSettingsAndroid =
        new AndroidInitializationSettings('app_icon');
    var initializationSettingsIOS = new IOSInitializationSettings();
    var initializationSettings = new InitializationSettings(
        initializationSettingsAndroid, initializationSettingsIOS);
    FlutterLocalNotificationsPlugin().initialize(initializationSettings, onSelectNotification: onSelectNotification);
  }

对于功能:

showNotification() async {
    var android = new AndroidNotificationDetails('Channel ID', 'Channel Name', 'channelDescription');
    var iOS = new IOSNotificationDetails();
    var platform = new NotificationDetails(android, iOS);
    await flutterLocalNotificationsPlugin.show(
      0, 'New Notification', 'Flutter Local Notif', platform,payload: 'test notification');
  }

错误是"PlatformException(PlatformException(错误,尝试在空对象引用上调用虚拟方法'int java.lang.Integer.intValue()'),空))"

The error is "PlatformException (PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null))"

我已经在文档和youtube上进行过尝试,但是我总是收到此错误消息

I've already tried on the documentation and also youtube, but I always get this error message

推荐答案

我已经遇到了这个问题,对于我来说,这是一个图标问题 app_icon
在您的 initState 函数中,将其替换为

I have faced this, and in my case it was an icon problem app_icon
in your initState function replace this

 var initializationSettingsAndroid = new AndroidInitializationSettings('app_icon');

与此

 var initializationSettingsAndroid = new AndroidInitializationSettings('@mipmap/ic_launcher');

希望这对您有所帮助.

这篇关于我的Flutter本地通知存在一些错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆