我想告诉我的应用从MainActivity的onCreate方法内的确定路由开始,如下所示:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
flutterView.setInitialRoute("anotherRoute") // <-- no result
}
但是它没有任何结果,飞镖侧面的静止图像会以window.defaultRouteName
的形式接收到标准的“ /”
如果我在调用super之前设置了它,它会给我NullPointer:
override fun onCreate(savedInstanceState: Bundle?) {
flutterView.setInitialRoute("anotherRoute") // <-- NullPointer
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
}
答案 0 :(得分:0)
您需要覆盖 createFlutterView 方法
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
}