Using 3.0.0-nullsafety.2
Describe the bug
When picking a file with withData set to true, the result has no bytes on the first pick (i.e. when permission is asked for and granted). Subsequent calls return a file with the expected bytes.
Platform
Platform OS version
Android 11
How are you picking?
final result = await FilePicker.platform.pickFiles(
allowedExtensions: ['gug'],
type: FileType.custom,
withData: true,
);
Details to reproduce the issue
Only seems to be an issue on first call.
Error Log
No apparent errors or meaningful output.
Flutter Version details
[✓] Flutter (Channel dev, 1.27.0-4.0.pre, on Linux, locale en_US.UTF-8)
• Flutter version 1.27.0-4.0.pre at /opt/flutter
• Framework revision f8cd24de95 (2 days ago), 2021-02-16 11:24:17 -0800
• Engine revision 1d537824d6
• Dart version 2.13.0 (build 2.13.0-30.0.dev)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /home/cranston/Android/Sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
Update. If I wrap my FilePicker.platform.pickFiles call with a call to request storage permissions using the permission_handler package, this issue seems to go away:
if (await Permission.storage.request().isGranted) {
// Call FilePicker.platform.pickFiles in here
}
@cranst0n oddly permissions are being asked before launching the picker itself which isn't launched unless the permissions are actually conceded.
I'll close this for now, but reopen if anyone else experiences the same.
Thank you!
@miguelpruivo I meant to post another update but must've slipped my mind. My last comment doesn't seem to be true, I must have not tracked my situation properly. I'm still hitting this issue.
@cranst0n weird then. By looking at Android's source everything is being done properly. One cannot access file explorer without first allowing access to the content. I don't really get why you can only access it on the second access though.
Which Android version are you trying on?
Android 11. I'll try again to recreate the issue next time I'm in front of a computer.
@miguelpruivo I've revisited this and can confirm I'm still running into this. I've tried using both local files on the phone, as well as picking files from Google Drive. Picking the file the first time fails to include bytes, in both scenarios and succeeds in subsequent picks.
@cranst0n ill give it a try.
Just an FYI, running the same code on ios works fine for me.
I have this problem as well. For me this happens on the first call as well as occasionally without a noticeable pattern.
As a workaround, I added a check to see if the bytes are missing, and then manually read them from the file.
I don't see a reason why this should happen. Looks like those "Android nuances" that can't be properly replicated.
If you manage to replicate this perfectly, please, provide me with a sample so I can work in a fix — or at least, give me the steps.
Thank you.