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 unfortunately closes on Android when using Predictive Back or the hardware back button #2059

Open
Jasco07122021 opened this issue Sep 13, 2024 · 10 comments

Comments

@Jasco07122021
Copy link

The app unfortunately closes on Android when using Predictive Back or the hardware back button

  • Flutter 3.24.2
  • auto_route 9.2.2

I have 5 tabs and I use AutoTabsScaffold to manage them. Whenever I tap on the second or other tab, the hardware back button takes me back to the first tab. But, after pressing the back button, the app exits. Need fix!

This issue started after I upgraded my Flutter version to 3.24

@cdobrovolny
Copy link

having the same issue.

@AlexDochioiu
Copy link

Same issue here

@cdobrovolny
Copy link

a valid workaround is to downgrade the Flutter-Sdk to 3.22.0

@xVemu
Copy link

xVemu commented Oct 24, 2024

Current workaround is to pass custom onNavigationNotification in MaterialApp.router constructor.

MaterialApp.router(
  onNavigationNotification: _defaultOnNavigationNotification,
);

bool _defaultOnNavigationNotification(NavigationNotification _) {
  switch (WidgetsBinding.instance.lifecycleState) {
    case null:
    case AppLifecycleState.detached:
    case AppLifecycleState.inactive:
    // Avoid updating the engine when the app isn't ready.
      return true;
    case AppLifecycleState.resumed:
    case AppLifecycleState.hidden:
    case AppLifecycleState.paused:
      SystemNavigator.setFrameworkHandlesBack(true); /// This must be `true` instead of `notification.canHandlePop`, otherwise application closes on back gesture.
      return true;
  }
}

@ddfreiling
Copy link

Seems related to flutter/flutter#156517

@GregUAs
Copy link

GregUAs commented Oct 24, 2024

With Flutter 3.24.3, all versions above 8.1.3 are defective for the back gesture in Android.

@TiesPol
Copy link

TiesPol commented Oct 24, 2024

Same issue here, only when using FlutterFragmentActivity

@GregUAs
Copy link

GregUAs commented Oct 24, 2024

Should I pass through something else? @TiesPol

@LiamMarega
Copy link

Any solution?

@AlexDochioiu
Copy link

Any solution?

This one seems to work:
#2059 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants