flutter 问题与工艺路线名称有关

qpgpyjmq  于 2023-03-19  发布在  Flutter
关注(0)|答案(1)|浏览(147)

为什么当我杀死项目,它显示点击文本,但当我刷新它写在中心页rote未定义的意思是开关情况下的语句是默认的。它重复所有的时间为什么??任何人都可以请解决我的问题

class Routes{
  static Route<dynamic> generateRoute(RouteSettings settings){
    switch(settings.name){
      case RoutesName.home:
        return MaterialPageRoute(builder: (context)=>home_screen());

      case RoutesName.login:
        return MaterialPageRoute(builder: (context)=>login());
      default:
        return MaterialPageRoute(builder: (context){
          return Scaffold(
            body: Center(child: Text("No Rote defined"),),
          );
        });
    }
  }
}
class RoutesName{
  ///account routes name
  static const String login="login";
  ///home-screen routes name
  static const String home="home_screen";

}
return Scaffold(
      body: Center(child: InkWell(
          onTap: (){
            utils.flushBarErrorMessage("No internet connection", context);

          },
          child: Text("Click"))),
    );
return const MaterialApp(
      debugShowCheckedModeBanner: false,
      themeMode: ThemeMode.dark,
    home: login(),
      onGenerateRoute: Routes.generateRoute,
    );
yiytaume

yiytaume1#

initialRoute
在您的MaterialApp中丢失,这可能是您的应用程序bug的原因.虽然,这里是我的个人代码参考,

class Routes {
  static MaterialPageRoute generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case RoutesName.homeScreen:
        return MaterialPageRoute(
          builder: (context) => const HomeView(),
        );
      case RoutesName.loginScreen:
        return MaterialPageRoute(
          builder: (context) => LoginView(),
        );
        
      case RoutesName.splashScren:
        return MaterialPageRoute(
          builder: (context) => const SplashView(),
        );
      case RoutesName.signupScreen:
        return MaterialPageRoute(
          builder: (context) => SignUp(),
        );
      default:
        return MaterialPageRoute(
          builder: (context) => const Scaffold(
            body: Center(
              child: Text('No Routes Defined!'),
            ),
          ),
        );
    }
  }
}

 child: const MaterialApp(
        title: 'Flutter Demo',
        initialRoute: RoutesName.splashScren,
        onGenerateRoute: Routes.generateRoute,
      ),

相关问题