[英]Can I use flutter assets for local notification attachments on iOS
I am using the flutter_local_notifications package to show notifications in my flutter app.我正在使用 flutter_local_notifications package 在我的 flutter 应用程序中显示通知。 I would like to show an image with my notifications on iOS by adding the image to the "attachments" array in IOSNotificationDetails.
我想通过将图像添加到 IOSNotificationDetails 中的“附件”数组中,在 iOS 上显示带有通知的图像。
final iosNotificationDetails = IOSNotificationDetails(
attachments: [IOSNotificationAttachment('assets/image.png')],
);
I have seen the example to download the image from a URL and save it in the application documents directory, but would like to know if there is a way to either load an image directly from the flutter assets or from a file in my iOS project.我已经看到了从 URL 下载图像并将其保存在应用程序文档目录中的示例,但想知道是否有一种方法可以直接从 flutter 资产或从我的 Z1BBZDF605991920DB11CBDF8508 项目中的文件加载图像。
import 'dart:async';导入“飞镖:异步”; import 'dart:io';
导入“飞镖:io”;
import 'package:flutter/services.dart' show rootBundle;导入 'package:flutter/services.dart' 显示 rootBundle; import 'package:path_provider/path_provider.dart';
导入'包:path_provider/path_provider.dart';
Future getImageFileFromAssets(String path) async { final byteData = await rootBundle.load('assets/$path'); Future getImageFileFromAssets(String path) async { final byteData = await rootBundle.load('assets/$path');
final file = File('${(await getTemporaryDirectory()).path}/$path');最终文件 = File('${(await getTemporaryDirectory()).path}/$path'); await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
等待 file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
return file;返回文件; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.