我无法访问 providerScope 以允许我的导航路线依赖于未来

问题描述

我正在尝试使深层链接正常工作,但我不得不从 navigator 1.0 迁移。我目前的身份验证解决方案是依赖于导航 1.0。我决定在导航 2.0 中使用 routemaster。

 home: FutureBuilder<bool>(
              future: hasUserLogged(),builder: (context,snapshot) {
                switch (snapshot.connectionState) {
                  case ConnectionState.none:
                  case ConnectionState.waiting:
                    return PlatformScaffold(
                      body: Center(
                        child: Container(
                            width: 100,height: 100,child: PlatformCircularProgressIndicator()),),);
                  default:
                    if (snapshot.hasData && snapshot.data!) {
                      return MyBottomNavBar();
                    } else {
                      return LoginPage();
                    }
                }
              }),

现在我需要使用我相信的提供者访问所有相同的数据。所以我尝试这样做并修改hasUserLogged()。

 Future<bool> hasUserLogged() async {
    ParseUser? currentUser = await ParseUser.currentUser() as ParseUser?;
    if (currentUser == null) {
      context.read(userStateProvider).logout();
      return false;
    }
    //Checks whether the user's session token is valid
    final ParseResponse parseResponse =
        (await ParseUser.getCurrentUserFromServer(
            currentUser.get<String>('sessionToken')!))!;

    if (!parseResponse.success) {
      //Invalid session. logout
      await currentUser.logout();
      context.read(userStateProvider).logout();
      return false;
    } else {
      context.read(userStateProvider).logIn();
      return true;
    }
  }

然后做这个

    routesBuilder: (context) {
      // Return the correct routing map depending on the current login state
      switch (context.read(userStateProvider).loggedInState) {
        case LoggedInState.loading:
          return initializingRoutes;
        case LoggedInState.loggedOut:
          return loggedOutRoutes;
        case LoggedInState.loggedIn:
          return loggedInRoutes;
      }
    },);

现在我收到一个错误,因为没有找到 ProviderScope,我很困惑如何在 myApp 之前使用 providerScope 或者这里的最佳解决方案是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)