我想使用flutter在通知中显示一个小部件。我正在使用令人敬畏的通知包,但我无法实现同样的效果。
Future<void> triggerNotification() async{
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 1,
channelKey: 'key1',
title: 'This is Notification title',
body: 'This is Body of Noti',
bigPicture: 'https://protocoderspoint.com/wp-content/uploads/2021/05/Monitize-flutter-app-with-google-admob-min-741x486.png',
notificationLayout: NotificationLayout.BigPicture
),
);
}
在这个片段中有一个bigPicture参数,它需要图像的url。我已经使用重新绘制边界将小部件转换为图像。有没有什么方法可以传递图像小部件而不是url?非常感谢。
您可以使用Uri.file构造函数。下面是一个使用相机文件的例子。
Future<void> triggerNotification() async {
final PickedFile pickedFile = await _picker.getImage(source: ImageSource.camera);
Uri uri = Uri.file(pickedFile.path);
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 1,
channelKey: 'basic_channel',
title: 'This is Notification title',
body: 'This is Body of Noti',
bigPicture:
uri.toString(),
notificationLayout: NotificationLayout.BigPicture),
);
}