我有一个现有的android应用程序,并且在我的项目中集成了flutter,我想调用在我的主要方法中定义的flutter特定路线
class FlutterView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Platform View',
initialRoute: '/',
routes: {
'/': (context) => HomeScreen(),
'/secound': (context) => MyCustomForm(),
'/dashboard': (context) => DashBoardScreen(),
'/login': (context) => LoginScreen(),
},
theme: new ThemeData(
primarySwatch: Colors.red,
textSelectionColor: Colors.red,
textSelectionHandleColor: Colors.red,
),
);
}
}
从我的android活动中,我正在这样叫flutter活动
startActivity(new Intent(this,FlutterActivity.class));
它的确打开了flutter活动,但是使用了initialRoute:'/'很好,但是有一段时间我想在打开flutter活动时针对eg('/ dashboard')路线打开它,我该怎么做? / p>
答案 0 :(得分:0)
Navigator.of(yourContext).pushNamed('/<route-name>')
答案 1 :(得分:0)
如here所述,从Android:
Intent intent = new Intent(context, MainActivity.class);
intent.setAction(Intent.ACTION_RUN);
intent.putExtra("route", "/routeName");
context.startActivity(intent);
在Flutter中,使用android_intent
:
AndroidIntent intent = AndroidIntent(
action: 'android.intent.action.RUN',
// Replace this by your package name.
package: 'app.example',
// Replace this by your package name followed by the activity you want to open.
// The default activity provided by Flutter is MainActivity, but you can check
// this in AndroidManifest.xml.
componentName: 'app.example.MainActivity',
// Replace "routeName" by the route you want to open. Don't forget the "/".
arguments: {'route': '/routeName'},
);
await intent.launch();
请注意,该应用程序只有在终止时才会在此路由中打开,也就是说,如果该应用程序处于前台或后台,则不会在指定的路由中打开。