firebase - signOut() does not work after i navigate to a screen..but it works when i do not navigate.. how can i fix this?
问题描述
I have two pages in my app which are shown after the sign in process, Home() and Edit(). Edit() page can be accessed through the bottom navigation bar in Home() page. In the edit page ,user can press 'OK' after editing. When the user presses "OK", the screen changes to Home() page, where the changes are shown. Once this process is done, the signOut() button in the Home() page does not work. If the user does not press "OK " in Edit() page after sign in process, the signOut() button works alright. How can i fix this?
The onPressed() {} for the "OK " is shown below.
onPressed() {
// also the form data saving to database.
Navigator.popAndPushNamed(context, HomeScreen.id);
}
解决方案
你应该如下:
onPressed: () {
FirebaseAuth auth = FirebaseAuth.instance;
auth.signOut().then((res) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => SignIn()),
);
});
},
onPressed
在按钮的此处signOut
,用户退出 firebase,因此将没有当前用户,您将导航到不同的页面。
推荐阅读
- javascript - 如何检查特定服务器中的角色?
- r - ANOVA + 聚类标准化效应
- reactjs - 刷新后 React.js 道具变为未定义
- apache-spark - 如何将我的输出作为每次运行的新行插入
- javascript - socket.io 客户端:没有“连接”、“错误”......事件被触发 - 只有消息
- reactjs - 如何将 GraphQL 中的数组映射到 ResourceList 元素?
- c# - 从 Razor 页面中的 POST 方法激活时,UseStatusCodePagesWithReExecute 错误地呈现错误页面
- python - sys.argv 在 cython exe 中是不可理解的
- python - 如何从某个文件夹上传所有文件并将它们存储为变量
- embedded-linux - 带有 RTC 板的 Tinkerboard 不更新系统时间