Flutter filepicker android singleInstance mode it is returns file path as null

162 Views Asked by At

I am using the flutter file picker 6.0.0.When i try to select file from the picker file.I used singleInstance in manifest.

 FilePickerResult? result = await FilePicker.platform.pickFiles(allowedExtensions: ['jpg','jpeg','png','pdf'],type: FileType.custom);
if (result != null) {
  File file = File(result.files.single.path!);
  controller.isPasswordProtected.value =
      await FileHelper.checkFileIsPasswordProtected(file);
  controller.fileSelected(file);
  controller.uploadDocument();
}
1

There are 1 best solutions below

0
Alann Maulana On BEST ANSWER

It looks like this is expected behavior on Android, you can see here. If the calling app forbids other activities in its task, then it can't get results from other activities.

Related flutter plugin image_picker is also mentioning about singleInstance launch mode :

Launching the image picker from an Activity with launchMode: singleInstance will always return RESULT_CANCELED. In this launch mode, new activities are created in a separate Task. As activities cannot communicate between tasks, the image picker activity cannot send back its eventual result to the calling activity. To work around this problem, consider using launchMode: singleTask instead.

Read the details here