本文介绍了我的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');
  }

我已经在文档和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本地通知存在一些错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:47