【问题标题】:Flutter: How to remove all previous routes when auth steam change state?Flutter:当身份验证蒸汽改变状态时如何删除所有以前的路由?
【发布时间】:2022-10-07 18:33:44
【问题描述】:

我想删除所有以前的路线并返回#WelcomeScreen 如果 API 响应 401

代码

return GetMaterialApp(
        scrollBehavior: Behavior(),
        defaultTransition: Transition.leftToRight,
        translations: LanguageService(),
        locale: Get.locale,
        fallbackLocale: const Locale(\'en\', \'US\'),
        debugShowCheckedModeBanner: false,
        home: Obx(
          () {
            if (controller.state is Authenticated) {
              return const MainScreen();
            } else if (controller.state is UnAuthenticated) {
              return WelcomeScreen();
            } else if (controller.state is AuthSignIn) {
              return SignInScreen();
            } else if (controller.state is AuthSignUp) {
              return SignUpScreen();
            } else {
              return const SplashScreen();
            }
          },
        ),
        theme: AppTheme.light,
        darkTheme: AppTheme.dark,
        getPages: AppPages.list);

控制器

AuthController auth = Get.find();
Future<void> fetchUsers() async{
    var response = await userService.findAll();
    //......
    if(response.code==401){
       auth.authStateStream.value = UnAuthenticated();
       Get.back();
       Get.back();

    }

}

目前,在状态更改为 UnAuthenticated 时,它会返回 WelcomeScreen 但它不会删除一些以前的页面。我需要使用 Get.back 一个或多个,具体取决于我推送的页面。

有没有更好的解决方案,请给我一个建议或建议。 谢谢!

    标签: flutter flutter-getx


    【解决方案1】:

    你可以做 :

    Get.offAll(()=>WelcomeScreen());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      • 2019-11-05
      • 2019-12-05
      相关资源
      最近更新 更多