我正在我的Flutter应用程序中实现身份验证流程 .
登录尝试后,将使用以下代码打开CheckAuth(检查用户是否已登录,然后打开主屏幕或相应地注册屏幕):
void _signIn() async {
await _auth
.signInWithEmailAndPassword(
email: _userEmail.trim(), password: _userPassword.trim())
.then((task) {
// go to home screen
if (task.getIdToken() != null) {
setState(() {
Navigator.pushReplacement(
context,
new MaterialPageRoute(
builder: (BuildContext context) => new CheckAuth()));
});
} else {
print("Authentication failed");
}
});
}
问题:我可以成功登录该应用,但如果我在登录后点击后退按钮,则会返回到登录屏幕(我希望它从应用中退出) .
问题: How to move from one screen to another in Flutter without the way back?
我是否需要以某种方式删除导航器历史记录?或者根本不使用导航仪?我尝试了Navigator.replace方法,但似乎没有用 .
2 回答
离开auth屏幕时也需要使用
Navigator.pushReplacement
. 不仅仅是在重定向到登录页面时 .你需要使用
_context
的对象BuildContext
和page
是您指向的页面 .