Flutter:有关命名和初始路线的问题

问题描述 投票:0回答:1

如果我使用命名路线和初始路线,则不能使用home参数,这是否意味着我将不得不在我为应用创建的每个新屏幕上创建支架和材料应用小部件?

android mobile flutter flutter-layout
1个回答
0
投票

不,你不。给出示例

    class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: 'inicio',
      routes: <String, WidgetBuilder>{
        'tabs': (BuildContext context) => TabsPage(),
        'eventos': (BuildContext context) => EventosPage(),
        'agenda': (BuildContext context) => AgendaPage(),
        'sobre': (BuildContext context) => SobrePage(),
        'palestrantes': (BuildContext context) => PalestrantesPage(),
        'inicio': (BuildContext context) => InicioPage(),
        'hoteis': (BuildContext context) => HoteisPage(),
        'restaurantes': (BuildContext context) => RestaurantesPage(),
        'info': (BuildContext context) => InfoPage(),
        'homeParticipante': (BuildContext context) => HomeParticipante(),
        'qr': (BuildContext context) => QrPage(),
      },
      title: 'Siepex App',
    );
  }

每条路线都会返回一个小部件(通常是一个脚手架),并将其作为子代安装在materialApp上。

© www.soinside.com 2019 - 2024. All rights reserved.