[英]File picker type image returns null flutter
I have a problem with file picker type image.我对文件选择器类型图像有疑问。 when I specify the type of the file as image file the function returns null , but when I specify an other type ,it returns the path file.
当我将文件类型指定为图像文件时,该函数返回 null ,但当我指定其他类型时,它返回路径文件。
File picker without type : - code :没有类型的文件选择器: -代码:
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
PlatformFile file = result.files.first;
print(file.name);
print(file.bytes);
print(file.size);
print(file.extension);
print(file.path);
} else {
print("null);
}
return imagepath : /data/user/0/com.tanitweb.divadeep/cache/file_picker/images.jpeg返回图像路径:/data/user/0/com.tanitweb.divadeep/cache/file_picker/images.jpeg
And when add type of file in the same code it returns null当在同一代码中添加文件类型时,它返回 null
File picker withtype :文件选择器类型:
> FilePickerResult? result = await FilePicker.platform.pickFiles(type: FileType.image);
if (result != null) {
PlatformFile file = result.files.first;
print(file.name);
print(file.bytes);
print(file.size);
print(file.extension);
print(file.path);
} else {
print("null);
}
return null返回空
Solution is simple, just add: withData: true解决方法很简单,只要加上:withData: true
FilePickerResult? result;
result = await FilePicker.platform.pickFiles(
type: FileType.image,
withData: true
);
Add the below line on project root/ios/Podfile before the line target 'Runner' do.
在项目 root/ios/Podfile上添加以下行,然后在目标
'Runner' do.
Pod::PICKER_MEDIA = false, resp. Pod::PICKER_AUDIO = false, resp. Pod::PICKER_DOCUMENT = false
After added, the code should look like this添加后,代码应该是这样的
Pod::PICKER_MEDIA = false, resp. Pod::PICKER_AUDIO = false, resp. Pod::PICKER_DOCUMENT = false
target 'Runner' do
use_frameworks!
use_modular_headers!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.