79136548

Date: 2024-10-29 09:36:20
Score: 0.5
Natty:
Report link

I found that if I change class MainActivity: FlutterActivity() instead of class MainActivity: FlutterFragmentActivity() {} The navigation works PERFECT. The problem is that I need my app to use FlutterFragmentActivity since I'm using STRIPE.

This is a solution that is working for me for now is to create custom onNavigationNotification in MaterialApp.router constructor.

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;
  }
}

And then:

MaterialApp.router(
  onNavigationNotification: _defaultOnNavigationNotification,
);
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Liam Marega