簡體   English   中英

如何從 Android 活動導航到特定的顫動路線?

[英]How to navigate to a specific flutter route from an Android activity?

我有一個現有的 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 活動

開始活動(新意圖(這個,FlutterActivity.class));

它確實打開了我的顫動活動,但使用了 initialRoute: '/' 這很好,但有時我想在打開顫動活動時打開例如(“/儀表板”)路線,我該怎么做?

在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();

請注意,應用程序只有在終止時才會在此路徑中打開,即,如果應用程序處於前台或后台,則不會在指定的路徑中打開。

只需創建一個方法通道並從 Android 調用 flutter 函數即可。 在該功能中,將您的應用程序從顫動導航到您想要的任何位置。

有關如何使用方法通道在顫振和本機代碼之間進行通信的更多信息,反之亦然。 請看一看

https://flutter.dev/docs/development/platform-integration/platform-channels

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM