【问题标题】:Flutter Firebase signoutFlutter Firebase 注销
【发布时间】:2018-11-30 14:01:14
【问题描述】:

一旦用户从应用程序中退出,我试图让他们返回登录页面,但是天哪,没有任何效果。我收到Bad state: Future already completed 之类的异常,或者应用程序返回登录屏幕,但当我回击时,前一个屏幕仍然存在于堆栈中。

这是我的代码:

_logOut() async{
    await _auth.signOut().then((value){
      print("***** log out");
      //Navigator.pop(context);
      //Navigator.popUntil(context, ModalRoute.withName("/login"));
      Navigator.pushReplacement(context, new MaterialPageRoute(builder: (context)=>new MyApp()));
    });
   // Navigator.popUntil(context, ModalRoute.withName("/login"));
  }

【问题讨论】:

  • 您应该为此使用 Navigator.push 和 Navigator.pop。

标签: firebase dart firebase-authentication flutter


【解决方案1】:

您不应在用户退出后手动将其发送到登录页面。相反,您应该听取用户的身份验证状态更改,并根据他们的身份验证状态选择应该向用户显示的页面。

在此处查看我的答案以获取更多详细信息: Firebase Login with Flutter using onAuthStateChanged

【讨论】:

    【解决方案2】:

    在尝试了Navigator 的所有功能后,终于成功了:

    _logOut() async{
        await _auth.signOut().then((_){
          Navigator.of(context).pushNamedAndRemoveUntil("/login", ModalRoute.withName("/home"));
        });
      }
    

    【讨论】:

      【解决方案3】:

      尝试使用以下代码

      Navigator.pushReplacementNamed(context, routeName)
      

      【讨论】:

        猜你喜欢
        • 2020-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-14
        • 2018-10-23
        • 2020-08-09
        • 2022-01-04
        • 1970-01-01
        相关资源
        最近更新 更多