[英]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.