Flutter 我需要在颤振应用程序中的何处存储照片图像?
我有一个可以拍照的应用程序 我需要将照片存储在我所有资产/图像/照片所在的位置 所以基本上我的问题是: a) 如何找到这些资产所在的路径(在电话上)? b) 如何将文件添加到同一路径Flutter 我需要在颤振应用程序中的何处存储照片图像?,flutter,dart,Flutter,Dart,我有一个可以拍照的应用程序 我需要将照片存储在我所有资产/图像/照片所在的位置 所以基本上我的问题是: a) 如何找到这些资产所在的路径(在电话上)? b) 如何将文件添加到同一路径 谢谢据我所知,您不能将图像存储在资产包中。只是因为当我们在资产文件夹为只读后构建android/ios应用程序时 您需要将图像存储在本地移动存储或云或捕获内存中 1) 您可以使用以下命令获取存储路径: Future<String> getStorageDirectory() async {
谢谢据我所知,您不能将图像存储在资产包中。只是因为当我们在资产文件夹为只读后构建android/ios应用程序时 您需要将图像存储在本地移动存储或云或捕获内存中 1) 您可以使用以下命令获取存储路径:
Future<String> getStorageDirectory() async {
if (Platform.isAndroid) {
return (await getExternalStorageDirectory()).path; // OR return "/storage/emulated/0/Download";
} else {
return (await getApplicationDocumentsDirectory()).path;
}
}
createImage() async{
String dir= getStorageDirectory();
File directory = new File("$dir");
if (directory.exists() != true) {
directory.create();
}
File file = new File('$directory/image.jpeg');
var newFile = await file.writeAsBytes(/* image bytes*/);
await newFile.create();
}