我按照 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)
我不知道要修复什么,因为没有描述。
请帮忙!谢谢!
终于发现问题所在了,这一行:
bigPicture: 'assets://assets/frediLogoSlogan.png'
应该是:
bigPicture: 'asset://assets/frediLogoSlogan.png',
仅当我在android模拟器上尝试时才会给出错误描述。所以尝试一下没有给出错误描述。
确保您已初始化并请求显示通知的权限
await AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
AwesomeNotifications().requestPermissionToSendNotifications();
}
});