【问题标题】:How to create full screen dialog in flutter when I am using root names to Navigate?当我使用根名称导航时,如何在颤振中创建全屏对话框?
【发布时间】:2023-03-14 11:13:01
【问题描述】:

这是使用 rootName 的示例代码,但在这里我无法使用 MaterialPageRoute 来获取 fullScreenDialog 属性。

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: '/',
      routes: {
        '/': (context) => MyHomePage(),
        '/under-development': (context) => UnderDevelopment(),
        '/profile1': (context) => Profile1()
      },
      title: appName,
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
          primaryColor: primaryColor,
          accentColor: secondaryColor,
          fontFamily: 'Poppins'),
    );
  }
}

导航器

onTap: () {
    Navigator.pushNamed(context, '/profile1');
},

【问题讨论】:

    标签: android ios dart flutter cross-platform


    【解决方案1】:

    您可以在 Material App 中使用类似的东西。希望对你有帮助。

    onGenerateRoute: (RouteSettings settings) {
            List<String> pathElements = settings.name.split("/");
            if (pathElements[0] != "") return null;
            switch (pathElements[1]) {
              case "home":
              String userID = pathElements[2];  
                return MaterialPageRoute(
            builder: (context) => ReportsPage(
                  userID: userID,
                ),fullscreenDialog: true);
    
            }
          },
    

    【讨论】:

      【解决方案2】:
      new MaterialApp(
          title: 'Named Routes Demo', 
          theme: ThemeData(
          primarySwatch: Colors.green), 
          initialRoute: '/', 
          onGenerateRoute: (RouteSettings settings) {
            List<String> pathElements = settings.name.split("/");
            if (pathElements[0] != "") return null;
            switch (pathElements[1]) {
              case "":
                return MaterialPageRoute(
                    builder: (context) => FirstScreen());
              case "second":
                return MaterialPageRoute(
                    builder: (context) => SecondScreen(), fullscreenDialog: true);
              case "third":
                return MaterialPageRoute(
                    builder: (context) => ThirdScreen(), fullscreenDialog: true);
          }
        },
      )
      

      导航按钮

      onTap: () {
          Navigator.pushNamed(context, '/second');
      },
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-11-21
        • 2020-11-01
        • 2020-10-10
        • 2022-06-16
        • 2021-04-21
        • 2019-01-25
        • 2019-02-17
        相关资源
        最近更新 更多