如何从Android活动导航到特定的扑扑路线? [英] How to navigate to a specific flutter route from an Android activity?

查看:79
本文介绍了如何从Android活动导航到特定的扑扑路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的android应用程序,并且在我的项目中集成了flutter,我想调用在我的主要方法中定义的flutter特定路线

I have an existing android application and i have integrated flutter in my project i want to call a flutter specific route which i define in my main method like this

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活动

from my android activity i am calling flutter activity like this

startActivity(new Intent(this,FlutterActivity.class));

startActivity(new Intent(this,FlutterActivity.class));

它确实打开了我的flutter活动,但使用initialRoute:'/'很好,但是有一段时间我想在打开flutter活动时打开eg('/ dashboard')路线,怎么办?

it does open my flutter activity but with the initialRoute: '/' which is fine but some time i want to open for eg( '/dashboard') routes when i open a flutter activity how can i do it ??

推荐答案

从Android,如所述这里

From Android, as stated here:

Intent intent = new Intent(context, MainActivity.class);
intent.setAction(Intent.ACTION_RUN);
intent.putExtra("route", "/routeName");
context.startActivity(intent);

从Flutter,使用 android_intent

From Flutter, using 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();

请注意,只有在终止应用程序的情况下,该应用程序才会在此路由中打开该应用处于前景或背景中,将无法在指定的路径中打开。

Notice that the app is going to open in this route only if it's terminated, that is, in case the app is in foreground or background, it won't open in the specified route.

这篇关于如何从Android活动导航到特定的扑扑路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆