'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.
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
And when add type of file in the same code it returns 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 1:[1]
Solution is simple, just add: withData: true
FilePickerResult? result;
result = await FilePicker.platform.pickFiles(
type: FileType.image,
withData: true
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mamena tech |