Oussama Ridéne
Oussama Ridéne

Reputation: 362

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

Upvotes: 2

Views: 2784

Answers (2)

Navin Kumar
Navin Kumar

Reputation: 4027

Add the below line on project root/ios/Podfile before the line target 'Runner' do.

Pod::PICKER_MEDIA = false, 
Pod::PICKER_AUDIO = false, 
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!

Upvotes: -3

mamena tech
mamena tech

Reputation: 605

Solution is simple, just add: withData: true

FilePickerResult? result;

result = await FilePicker.platform.pickFiles(
 type: FileType.image,
 withData: true
 );

Upvotes: 4

Related Questions