ajinasokan / flutter_fgbg

Flutter plugin to detect when app(not Flutter container) goes to background or foreground
MIT License
81 stars 34 forks source link

Plugin reporting that the app is in background, while opening take image and pick Image. #5

Open madhav11194 opened 2 years ago

madhav11194 commented 2 years ago

I tried running the example project in android emulator and it is giving same result as AppLifeCycleState. i.e, showing that the app is in background for image picker and then foreground when image picker is closed. Screenshot_1638420688

ajinasokan commented 2 years ago

Yes there seems to be a problem. Will investigate this.

ajinasokan commented 2 years ago

It seems image picker is now opening a different app/package for both camera(opens camera app) and file picking(open file manager) and not an activity on top of Flutter app. So app IS going to background that's why the plugin reported that way as well.

I guess now it will be useful only in case of the biometric auth flow or any other lib that has activity based pickers.

madhav11194 commented 2 years ago

Thank you ajin for replying. So now I'm using AppLifeCycleState only. And the function which is opening image picker, I am using an if/else conditional, to not the call the required function, which I need to call for app inactivity, at that time. So, It's working fine.

ajinasokan commented 2 years ago

Alright. I will keep this issue open until we there is a proper fix/decision.

thorgexyz commented 2 years ago

flutter_fgbg is reporting that the app enters fg/bg when authenticating with passcode on my Android (ONEPLUS A5000 (mobile) • db8f9f95 • android-arm64 • Android 10 (API 29)) with local_auth

ajinasokan commented 2 years ago

@thorgexyz Does that open another app/activity that is not part of your app? Then it would report as foreground/background switch, because it is in fact a foreground/background switch.

What is not such a switch is, an overlay that shows up above your app or an activity/fragment that is part of the app showing above/instead of your Flutter view.

As I see more reports like this I'm assuming the manufacturers customize these things and this library is not very effective in every scenarios.

hatemragab commented 2 years ago

any progress?

abdallah-odeh commented 1 year ago

any progress yet? the plugin reports bg/fg switch when the user tries to pick an image from gallery or files, in android it fires that the app is in background it works fine when opening camera, in iOS it works perfectly

did you find a solution for that? or anyone has a workaround?

ajinasokan commented 1 year ago

I have written a workaround (read as a nasty hack I'm not proud of)

You can use the new FGBGEvents.ignoreWhile API like this:

FGBGEvents.ignoreWhile(() async {
    await picker.pickImage(source: ImageSource.gallery);
    // or do something else that can put app to background but don't want to be handled by flutter_fgbg
});

Any background foreground switches while the closure is executing will be suppressed. This is available in the master. Test it with this in pubspec and let me know if it works, I will make a new release.

    flutter_fgbg:
        git:
            url: https://github.com/ajinasokan/flutter_fgbg
            commit: 19957b21bcf26bbc85cd73e02008afa053ef5c2c
abdallah-odeh commented 1 year ago

Thank you for the quick respond, will try that.