I want to tell to my app to start in a determined route inside the onCreate method of the MainActivity like this:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
flutterView.setInitialRoute("anotherRoute") // <-- no result
}
But it gives no results, the dart side stills receive the standard "/" as window.defaultRouteName
If I set it before calling super, it gives me NullPointer:
override fun onCreate(savedInstanceState: Bundle?) {
flutterView.setInitialRoute("anotherRoute") // <-- NullPointer
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
}
You need to override createFlutterView method
override fun createFlutterView(context: Context): FlutterView {
val matchParent = WindowManager.LayoutParams(-1, -1)
val view = FlutterView(this, null as AttributeSet?, this.createFlutterNativeView())
view.setInitialRoute("/route2")
view.layoutParams = matchParent
this.setContentView(view)
return view
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.