How to navigate to a specific flutter route from an Android activity?(如何从 Android 活动导航到特定的颤振路线?)
问题描述
我有一个现有的 android 应用程序,我已经在我的项目中集成了颤振我想调用一个颤振特定的路线,我在我的主要方法中定义这样的路线
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 活动中,我正在调用这样的颤动活动
from my android activity i am calling flutter activity like this
startActivity(new Intent(this,FlutterActivity.class));
startActivity(new Intent(this,FlutterActivity.class));
它确实打开了我的颤动活动,但使用 initialRoute: '/' 这很好,但有时我想打开例如('/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 活动导航到特定的颤振路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Android 活动导航到特定的颤振路线?


基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01