简体   繁体   English

注销 Flutter 应用程序不会返回登录页面

[英]Logging out of Flutter app doesn't go back to login page

I'm using firebase to authenticate users in my app, and login/signup, and logging out works correctly when I logout from the home page directly following the login page, but doesn't work when I logout from a settings page routed from the home page.我正在使用 firebase 对我的应用程序中的用户进行身份验证,并且登录/注册和注销在我直接从登录页面后的主页注销时正常工作,但在我从路由的设置页面注销时不起作用主页。

It is logged out on firebase, but the page won't go back to the login page immediately calling signout unless I press the back button on the appbar.它在 firebase 上注销,但页面不会立即返回登录页面调用注销,除非我按下应用栏上的后退按钮。

This is my signout function:这是我的注销功能:

abstract class BaseAuth {
  Future<void> signOut();
}

Future<void> signOut() async {
  return _firebaseAuth.signOut();
}

final BaseAuth auth;
final VoidCallback onSignedOut;

_signOut() async {
  try {
    await widget.auth.signOut();
    widget.onSignedOut();
  } catch (e) {
    print(e);
  }
}

In my root page, I have:在我的根页面中,我有:

@override
  Widget build(BuildContext context) {
    switch (authStatus) {
      case AuthStatus.NOT_DETERMINED:
        return _buildWaitingScreen();
        break;
      case AuthStatus.NOT_LOGGED_IN:
        return new LoginSignUpPage(
          auth: widget.auth,
          onSignedIn: _onLoggedIn,
        );
        break;
      case AuthStatus.LOGGED_IN:
        if (_userId.length > 0 && _userId != null) {
          return new HomePage(
            userId: _userId,
            auth: widget.auth,
            onSignedOut: _onSignedOut,
          );
        } else return _buildWaitingScreen();
        break;
      default:
        return _buildWaitingScreen();
    }
  }

So if the authenticaiton status is not logged in, it should return back to the LoginSignUpPage.因此,如果身份验证状态未登录,则应返回 LoginSignUpPage。

I'm not sure why this delay is happening.我不确定为什么会发生这种延迟。 Any help would be appreciated!任何帮助,将不胜感激!

So adding Navigator.popUntil(context, ModalRoute.withName("/"));所以添加Navigator.popUntil(context, ModalRoute.withName("/")); as the last line in _signOut() solved the issue.因为_signOut()中的最后一行解决了这个问题。

It simply pop all screens stacked on top of first screen in your stack.它只是弹出堆栈中第一个屏幕顶部堆叠的所有屏幕。

This is working for me这对我有用

Navigator.of(context, rootNavigator: true).pop(context); Navigator.of(context, rootNavigator: true).pop(context);

Try using PushReplacement, Even I use it when I get the issue and I don't have time to fix it, yeah it can be used as fix for the issue too!尝试使用 PushReplacement,即使我在遇到问题时使用它,但我没有时间修复它,是的,它也可以用作问题的修复!

Navigator.of(context).pushReplacement or pushNamedReplacement(Screen to navigate);

暂无
暂无

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

相关问题 使用 Twitter 登录不会将用户添加到 Flutter 上的 Firebase - Logging in with Twitter doesn't add user to Firebase on Flutter Stream flutter app注销再登录时数据不刷新 - Stream data is not refreshing when logging out and logging in with different user id in flutter app 在 Apache 超集中通过管理员登录时,它会将我重定向回登录页面 - While logging in through admin in Apache superset it redirects me back to login page Flutter web 应用程序收到推送通知,但浏览器未显示 - Flutter web app receives push notification but broswer doesn't show it 使用 otp 登录后应用程序崩溃,然后在注销后尝试 go 再次登录页面 - App crashing after loging in using otp once and then after logout trying to go to login page again 如何解决 flutter 中的“Target of URI doesn't exist package:flutter_facebook_login/flutter_facebook_login.dart”? - how to solve "Target of URI doesn't exist package:flutter_facebook_login/flutter_facebook_login.dart" in flutter? 中间件正在返回登录页面 - Middleware is returning back to login page Flutter 注销后应用登录 PostgresSQLException - Flutter app login after a logout PostgresSQLException Facebook 和 Google 登录不适用于 Android AAB 构建上传到 Firebase 应用程序分发 - Facebook and Google login doesn't work for Android AAB build uploaded to Firebase App Distribution React js go 登录后返回上一页 - React js go back to previous page after sign in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM