firebase - 退出 Flutter 应用程序不会返回登录页面
问题描述
我正在使用 firebase 对我的应用程序中的用户进行身份验证,并登录/注册,当我直接在登录页面之后从主页注销时,注销工作正常,但当我从路由的设置页面注销时无法正常工作主页。
它在firebase上注销,但除非我按下appbar上的后退按钮,否则页面不会立即返回登录页面调用signout。
这是我的注销功能:
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);
}
}
在我的根页面中,我有:
@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();
}
}
因此,如果身份验证状态未登录,它应该返回到 LoginSignUpPage。
我不确定为什么会发生这种延迟。任何帮助,将不胜感激!
解决方案
所以添加Navigator.popUntil(context, ModalRoute.withName("/"));
作为最后一行_signOut()
解决了这个问题。
它只是弹出堆栈中第一个屏幕顶部的所有屏幕。
推荐阅读
- android - Firebase ML-Kit 并行运行多个人脸检测会话
- cron - 具有固定延迟的 Cron 表达式
- android - Recyclerview 中的 Exoplayer 错误,源错误没有可用的提取器
- c - 在另一个结构中初始化结构数组
- javascript - 如何通过单击外部来关闭创建的 div?
- ssh - 将 gzip 发送到另一台使用 onKeyboardInteractive 和 node-ssh 的服务器
- javascript - 使用 Javascript 数据
- php - SOAP 请求返回“XML 消息字符串,但类是 com.sun.org.apache.xerces.internal.dom.ElementNSImpl 类”
- python - 从文件中读取字符串以查找唯一字符
- flutter - 如何获取 Pageview 中的页数以用于 Flutter 中的行指示器?