I'm adding flutter to a existing Android project and everything is working fine, except one thing:
My Android project has only one Flutter module. In that Flutter module I have two routes that will be shown in different parts of the Android project:
initialRoute: '/',
routes: {
'/': (_) => MyHomePage(),
'/settings': (_) => _SettingsPage()
}
In the Android Activity if I start a new Flutter activity with this:
startActivity(
FlutterActivity
.withCachedEngine(flutterEngineId)
.build(this)
)
It will start Flutter with the default page route (/
) which is the expected result. Then in this Flutter page if I navigate back, it will pop the Flutter engine and navigate back to the Android Activity. Everything good for now.
But if I start a Flutter activity with a custom initial route, and then I press the back button, it will not pop the Flutter engine and navigate to the Android activity but to the initial Flutter route (in this case the /
route).
startActivity(
FlutterActivity
.withNewEngine()
.initialRoute("/settings")
.build(this)
)
Why we're having this behavior if we are specifying the initial route while starting the FlutterActivity
?
And if this is the expect behavior, then what is the best way of make it navigate to the Android activity?