I'm experimenting with integrating a flutter module in an existing android app. Starting a view works fine using this code:
private fun startFlutterActivity() {
val intent = FlutterActivity.withCachedEngine("default_engine").build(this)
startActivity(intent)
}
But I'm not sure on how to pass additional data e.g. an id to fetch data for to the flutter component. I know you can establish a message channel but this seems like a lot of overhead for passing stuff around.
Using the File > New > New Module… menu in Android Studio in your existing Android project, you can either create a new Flutter module to integrate, or select an existing Flutter module that was created previously. If you create a new module, you can use a wizard to select the module name, location, and so on.
The easiest way is to pass the id through to the flutter engine via the initial route.
So like:
flutterEngine = new FlutterEngine(this);
// Configure an initial route.
flutterEngine.getNavigationChannel().setInitialRoute("showStuf?id=$id");
Or, in your example, you can simply add the intent extra FlutterActivityLaunchConfigs.EXTRA_INITIAL_ROUTE to the intent.
On the flutter side you would then simply parse the initial route in your onGenerateRoute
handler for your MaterialApp
or other navigator config.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With