我在flutter项目中成功使用save_in_gallery: ^0.1.3
包将图像保存到图库。
完成后,我将显示一个对话框,询问用户是否要打开文件。
如何从“打开” FlatButton打开'Flutter Images'
文件夹?
((我需要打开文件夹,因为您无法在iOS中命名图像文件,所以我希望用户打开该文件夹并可以查看所有已保存的图像)
await ImageSaver().saveImages(
imageBytes: [pngBytes], directoryName: 'Flutter Images').then((onValue) {
if (onValue) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Saved Completed'),
content: Text('Do you want to open your file?'),
actions: <Widget>[
FlatButton(
child: Text('Open'),
onPressed: () {}, //---> OPEN FOLDER FROM HERE <---
),
FlatButton(
child: Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
})
[pngBytes
是我实际上保存在图库内的'Flutter Images'
文件夹中的Uint8List。
您可以使用https://pub.dev/packages/open_file库从存储中打开任何文件。
OpenFile.open("path_to_file_here");
例如
OpenFile.open("/sdcard/Flutter Images/image.png");