flutter 分享代码(四)

2019-08-05  本文已影响0人  Victory_886
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.red,
      ),
      home: MyHomePage(),
      onGenerateRoute: onGenerateRoute,  /// 这里是配置路由
    );
  }
}

final routesMap = {
  "/root1": (context) => new MusicQQPage(),
  "/root2": (context) => new MusicXMPage(),
  "/root3": (context) => new MusicMainPage(),
};

var onGenerateRoute = (RouteSettings settings) {
  final String name = settings.name;
  final Function pageContentBuilder = routesMap[name];
  if (pageContentBuilder != null) {
    Route route;
    if (settings.arguments != null) {
      route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
    } else {
      route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
    }
    return route;
  }
};

Navigator.pushNamed(context, "/root1");
上一篇下一篇

猜你喜欢

热点阅读