Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The app is moved to inactive state when the file picker is presented on iOS #813

Closed
rohitrvayuz opened this issue Aug 31, 2021 · 17 comments
Closed
Assignees
Labels
improvement Improvement needed on a specific feature iOS Issue applies to iOS platform

Comments

@rohitrvayuz
Copy link

rohitrvayuz commented Aug 31, 2021

Describe the bug
The image picker or the document picker on iOS opens in new window and moves the app to inactive state and upon selecting the file it moves the app back to the resume state. The problem here is that I have a banking app which asks for PIN every time the app is resumed and due to this I am not able to implement the functionality. The default ImagePicker open the gallery modally on iOS but it does not support pdf files therefore I used your file_picker but it does not open the gallery and document picker modally.

Platform

  • [✅] iOS

Platform OS version
iOS 14.6

How are you picking?

try {
      FilePickerResult result =
       await FilePicker.platform.pickFiles(type: FileType.image);

       if (result != null) {
         File file = File(result.files.single.path);
         log('$file', name: 'Picker file');
       } else {
         // User canceled the picker
         log('User canceled the picker', name: 'Picker error');
       }
     } catch (e) {
       log('', name: 'Picker error', error: e);
    }

Flutter Version details

[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.2 20G95 darwin-arm, locale en-IN)
• Flutter version 2.2.3 at /Users/rohitrajput/flutter
• Framework revision f4abaa0735 (9 weeks ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/rohitrajput/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5.1, Build version 12E507
• CocoaPods version 1.10.1

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.59.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.25.0

[✓] Connected device (2 available)
• iPhone 12 Pro Max (mobile) • E52232D1-52A3-479D-A247-DC2798F51CAB • ios •
com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
• Chrome (web) • chrome • web-javascript • Google
Chrome 92.0.4515.159

• No issues found!
@miguelpruivo @jamesdixon @pchampio

@rohitrvayuz rohitrvayuz added the new issue An issue that hasn't yet been seen from the maintainer label Aug 31, 2021
@miguelpruivo
Copy link
Owner

Hum. The file_picker is also opened in a modal and the app is kept on background while doing the task of picking. Are you telling me that the image_picker doesn’t do that?

@rohitrvayuz
Copy link
Author

rohitrvayuz commented Aug 31, 2021

Hum. The file_picker is also opened in a modal and the app is kept on background while doing the task of picking. Are you telling me that the image_picker doesn’t do that?

@miguelpruivo Currently, both document picker and image/gallery picker on iOS are not being opened modally. They open on full screen and put the app in inactive state.

This is the log when I open the picker, select a file and then the picker closes

[log] app is inactive
[log] app is paused
[log] app is inactive
[App Lifecycle] app is resumed
2
[Lifecycle] AppLifecycleState.resumed
[Picker result] [/Users/username/Library/Developer/CoreSimulator/Devices/E52232D1-52A3-479D-A247-DC2798F51CAB/data/Containers/Data/Application/4190E9EB-7CB2-4CE0-B295-1CC6E5393215/tmp/com.app-Inbox/sample.pdf]
[Picker file] File: '/Users/username/Library/Developer/CoreSimulator/Devices/E52232D1-52A3-479D-A247-DC2798F51CAB/data/Containers/Data/Application/4190E9EB-7CB2-4CE0-B295-1CC6E5393215/tmp/com.app-Inbox/sample.pdf'

@miguelpruivo The image_picker opens the view modally without putting the app in background.

@miguelpruivo
Copy link
Owner

Ok, I'll take a look.

@rohitrvayuz
Copy link
Author

Ok, I'll take a look.

@miguelpruivo Thanks. Or if you could just guide me or tell me a hint where to look at then I can fork the repo and submit the pull request. I have never created packages for flutter before, that's why I am asking

@miguelpruivo
Copy link
Owner

@rohitrvayuz I'm right now looking into it, however, what is the plugin that you're saying that opens modally? Because the image_picker opens it exactly the same way as this one (using UIModalPresentationCurrentContext presentation).

Nevertheless, I can switch it for a modal.

@miguelpruivo miguelpruivo added improvement Improvement needed on a specific feature iOS Issue applies to iOS platform and removed new issue An issue that hasn't yet been seen from the maintainer labels Aug 31, 2021
@rohitrvayuz
Copy link
Author

@rohitrvayuz I'm right now looking into it, however, what is the plugin that you're saying that opens modally? Because the image_picker opens it exactly the same way as this one (using UIModalPresentationCurrentContext presentation).

Nevertheless, I can switch it for a modal.

flutter_document_picker 4.0.1
and
image_picker 0.8.3+3

@miguelpruivo
Copy link
Owner

You can see here that it's using the UIModalPresentationCurrentContext which displays the picker in a separate ViewController, hence, making the app going into background mode — exactly the same behaviour of the file_picker.

@miguelpruivo
Copy link
Owner

miguelpruivo commented Aug 31, 2021

I can update it to the desired behaviour, I'm just wondering how can it be since they are both using the same way of presentation when one is clearly using UIModalPresentationFormSheet.

The document_picker is using the automatic mode which can result in the modal sheet, yes.

@rohitrvayuz
Copy link
Author

rohitrvayuz commented Aug 31, 2021

I can update it to the desired behaviour, I'm just wondering how can it be since they are both using the same way of presentation when one is clearly using UIModalPresentationFormSheet.

@miguelpruivo Ok. Thanks.

The document_picker is using the automatic mode which can result in the modal sheet, yes.

Yes, this is what I want actually. Check this

@miguelpruivo
Copy link
Owner

I'm just surprised of image_picker displaying that way too, are you sure? Because by the code it doesn't look like it.

@miguelpruivo
Copy link
Owner

Done and published with 4.0.1. Let me know if it's good for you now. Thank you!

@rohitrvayuz
Copy link
Author

Done and published with 4.0.1. Let me know if it's good for you now. Thank you!

Thanks a lot @miguelpruivo. It is working as expected now.

@MsXam
Copy link

MsXam commented Sep 13, 2021

Unfortunately this PR will cause the FilePicker to fail and throw an exception if the user just swipes down the modal picker window rather than tapping cancel.

To reproduce :

  • Launch File Picker
  • Swipe Down
  • Launch File Picker again

If you encapsulate your code within a try..catch .. you will see the exception that is raised :

PlatformException: Multiple requests. Cancelled by a second request.

Sample code


    FilePickerResult fileResult;
    // FilePicker.platform.clearTemporaryFiles();
    try {
      if (DeviceHelper.isAndroid) {
        fileResult = await FilePicker.platform.pickFiles(
          type: FileType.any,
        );
      } else {
        fileResult = await FilePicker.platform
            .pickFiles(type: FileType.custom, allowedExtensions: [
          'ttf',
        ]);
      }
    } on Exception catch (e) {
      DialogHelper.alert(
          'File error', 'It was not possible to open the file', context);
      return;
    } 

The only solution if we still want to keep this new way of showing the modal dialog is to always do a :

FilePicker.platform.clearTemporaryFiles();

Prior to showing the dialog but then we loose the benefits of caching.

@miguelpruivo miguelpruivo reopened this Sep 13, 2021
@miguelpruivo
Copy link
Owner

@MsXam I might have to reset after dismissing. I’ll take a look.

@miguelpruivo miguelpruivo self-assigned this Sep 20, 2021
@alexda12
Copy link

@MsXam I have this also - do you have a fix for this ?

@miguelpruivo
Copy link
Owner

This has now been fixed with 4.1.1. Thank you all.

@Andrewcpu
Copy link

This seems to be the case on Android still, I'm loading files the same way as listed above and I'm on ^4.2.7. Upon calling pickFiles the AppState goes into paused, and upon returning becomes resumes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement needed on a specific feature iOS Issue applies to iOS platform
Projects
None yet
Development

No branches or pull requests

5 participants