Flutter main.dart initialRout 不工作

Flutter main.dart initialRout is not Working

我是这个框架的新手,这里的初始 Rout 不接受登录会话值请帮我解决这个问题。我尝试添加带有启动画面的主页,但它也不起作用我不明白这是怎么回事。

这是我的主页

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(),
        ),
      ],

在本页中使用 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(),
                },
              );
            },
          );
        },
      ),
    );
  }
}

您不能将 initialRoute 与路由映射一起使用,要么从路由映射中删除“/”,要么删除 initialRoute: