Flutter Awesome 通知 PlatformException 未知错误

问题描述 投票:0回答:2

我按照 ResoCoder 的指南了解如何设置与 Awesome Notifications Plugin 有关的所有内容。当我尝试创建新的基本通知时,此错误称为:

我的初始化代码

AwesomeNotifications().initialize('resource://drawable/res_notification_logo', [
NotificationChannel(
    channelKey: 'basic_channel',
    defaultColor: Colors.tealAccent,
    channelName: 'Basic '
        'Notifications',
    importance: NotificationImportance.High,
    channelShowBadge: true,
    channelDescription: 'Basic notifications for Fredi.')]);

我的呼叫通知代码

Future<void> createBasicNotification() async {
try {
        await AwesomeNotifications().createNotification(
       content: NotificationContent(
                id: createUniqueId(),
                channelKey: 'basic_channel',
                title: '${Emojis.money_coin} Test Notification Title',
                body: 'This is your first notification boy',
                bigPicture: 'assets://assets/frediLogoSlogan.png',
                notificationLayout: NotificationLayout.BigPicture));
      } on PlatformException catch (error) {
        print("$error");
      }
    }

然后我打电话:

onPressed: () async {
          print('pressed');
          await createBasicNotification();
        },

错误(输出)

pressed

flutter: PlatformException(exception, Unknow error, The operation couldn’t be completed. (awesome_notifications.AwesomeNotificationsException error 1.), null)

我不知道要修复什么,因为没有描述。

请帮忙!谢谢!

ios flutter notifications simulator awesome-notifications
2个回答
2
投票

终于发现问题所在了,这一行:

bigPicture: 'assets://assets/frediLogoSlogan.png'

应该是:

bigPicture: 'asset://assets/frediLogoSlogan.png',

仅当我在android模拟器上尝试时才会给出错误描述。所以尝试一下没有给出错误描述。


0
投票

确保您已初始化并请求显示通知的权限

    await AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
  if (!isAllowed) {
    AwesomeNotifications().requestPermissionToSendNotifications();
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.