在 Flutter 中使用 awesome_notifications 显示通知的问题

Kou*_*Deb 3 android dart flutter flutter-layout

我是 flutter 的新手。我已经开始创建一个提醒应用程序。我正在尝试在 android 警报回调上调用推送通知。我正在使用 awesome_notifications。回电时,我正在调用 _ringAlarm()。我已将其粘贴在下面。它说 D/NotificationSender(5192): 通知已创建但在屏幕上显示。

运行时抛出此异常。

W/System.err(5192):java.lang.IllegalArgumentException:无效通知(没有有效的小图标):通知(channel=basic_channel快捷方式=null contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x11 color= 0xff9d50dd vis=UNKNOWN(2))

Future _ringAlarm() async {

  AwesomeNotifications().initialize(
    'resource://drawable/logo.png',
    [
        NotificationChannel(
            channelKey: 'basic_channel',
            channelName: 'Basic notifications',
            channelDescription: 'Notification channel for basic tests',
            defaultColor: Color(0xFF9D50DD),
            ledColor: Colors.white
        )
    ]
  );

  AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
    if (!isAllowed) {
      AwesomeNotifications().requestPermissionToSendNotifications();
    }
  });

  AwesomeNotifications().createNotification(
    content: NotificationContent(
        id: 10,
        channelKey: 'basic_channel',
        title: 'Simple Notification',
        body: 'Simple body'
    )
  );

}
Run Code Online (Sandbox Code Playgroud)

Wor*_*lop 5

这意味着您的图标有一些问题要解决这个问题,您必须在“[project]/android/app/src/main/res/drawable/”下添加一个名为“logo.png”的图标。可绘制位置图像

初始化时,您必须只插入名称而没有像这样的扩展名

AwesomeNotifications().initialize(
    'resource://drawable/logo',
    [
        NotificationChannel(
            channelKey: 'basic_channel',
            channelName: 'Basic notifications',
            channelDescription: 'Notification channel for basic tests',
            defaultColor: Color(0xFF9D50DD),
            ledColor: Colors.white
        )
    ]
  );
Run Code Online (Sandbox Code Playgroud)

现在唯一可用的方法是通过资源