简体   繁体   English

Flutter main.dart initialRout 不工作

[英]Flutter main.dart initialRout is not Working

I'm New in this FrameWork and here initial Rout is not Accepting the Loggin Session value Please help me with this.我是这个框架的新手,这里的初始 Rout 不接受 Loggin Session 值请帮助我。 I tried to add Home with the splash screen but that also not working I'm not getting What's wrong in this.我尝试使用初始屏幕添加主页,但这也不起作用我没有得到这有什么问题。

This is my main Page这是我的主页

Future main() async {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    statusBarIconBrightness: Brightness.dark,
  ));
  runApp(Phoenix(child: AmericanCuisine()));
}

class AmericanCuisine extends StatefulWidget {
  @override
  _AmericanCuisineState createState() => _AmericanCuisineState();
}

class _AmericanCuisineState extends State<AmericanCuisine> {
  bool isLoggedIn;
  @override
  void initState() {
    super.initState();
    getData();
  }

  getData() async {
    WidgetsFlutterBinding.ensureInitialized();
    SharedPreferences storage = await SharedPreferences.getInstance();
    setState(() {
      isLoggedIn = storage.getBool("loggedIn");
    });
  }

  @override
  Widget build(BuildContext context) {
    
    return MultiBlocProvider(
      providers: [
        BlocProvider<LanguageCubit>(
          create: (context) => LanguageCubit(),
        ),
        BlocProvider<ThemeCubit>(
          create: (context) => ThemeCubit(),
        ),
      ],

in this page after using BlockBuilder how i To give the Initial Route在使用 BlockBuilder 后的此页面中,我如何给出初始路线

      child: BlocBuilder<ThemeCubit, ThemeData>(
        builder: (_, theme) {
          return BlocBuilder<LanguageCubit, Locale>(
            builder: (_, locale) {
              return MaterialApp(
                localizationsDelegates: [
                  const AppLocalizationsDelegate(),
                  GlobalMaterialLocalizations.delegate,
                  GlobalWidgetsLocalizations.delegate,
                ],
                supportedLocales: [
                  const Locale('en'),
                ],
                locale: locale,
                theme: theme,
                //This initial rout is not working.
                initialRoute: isLoggedIn == false ?'/': '/homeOrderAccount',                
                routes: {
                  // When navigating to the "/" route, build the FirstScreen widget.
                  '/': (context) => OpeningScreen(),
                  '/homeOrderAccount': (context) => HomeOrderAccount(),
                },
              );
            },
          );
        },
      ),
    );
  }
}

You can't use initialRoute with routes map either delete '/' from the routes map or delete the initialRoute:您不能将 initialRoute 与路线 map 一起使用,要么从路线 map 中删除“/”,要么删除 initialRoute:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM