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,
);