如何读取包含空格的文件路径?



我的保存图像方法:

_saveScreen() async {
RenderRepaintBoundary boundary =
_globalKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage();
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
final result =
await ImageGallerySaver.saveImage(byteData.buffer.asUint8List());
imageDateList.add('${dateTime.day}.${dateTime.month}.${dateTime.year}');
prefs.setStringList('imageDateList', imageDateList);
Navigator.of(context).pop();
String tmpStringHolder =
result.toString().split('storage')[1].split(',')[0];
photoData.addPhoto('storage$tmpStringHolder');
_toastInfo(result.toString());
}

我正在使用这些包来写入和读取映像文件:

image_picker: ^0.6.0+3
permission_handler: ^5.0.1+1
image_gallery_saver: ^1.6.7
path_provider: ^1.5.1+1

当我的应用程序名称中没有空格时,我的项目工作得很完美。现在,当我尝试加载图像时,我得到了这个错误:

'storage/emulated/0/Buttocks%20leg/1611320083489.jpg' (OS Error: No such file or directory, Errno = 2)

我尝试使用其他软件包,但我找不到任何解决方案。我试着读取这样的路径,但这也不起作用。

Image.file(File('"storage/emulated/0/Buttocks leg/1611553265363.jpg"')),

正如你在上面看到的我尝试的方式。当我尝试这个时,我得到这个错误:

Cannot open file, path = '"storage/emulated/0/Buttocks leg/1611553265363.jpg"' (OS Error: No such file or directory, errno = 2)

我必须读取文件名中包含空格的文件路径,我该怎么做?

尝试使用FileImage

的例子:

new FileImage(
new File('/storage/emulated/0/Buttocks leg/1611553265363.jpg')
);

最新更新