首页 > 解决方案 > 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);
}

标签: firebaseflutterdartfirebase-authenticationflutter-layout

解决方案


你应该如下:

        onPressed: () {
        FirebaseAuth auth = FirebaseAuth.instance;
        auth.signOut().then((res) {
            Navigator.pushReplacement(
            context,
            MaterialPageRoute(builder: (context) => SignIn()),
            );
        });
        },

onPressed在按钮的此处signOut,用户退出 firebase,因此将没有当前用户,您将导航到不同的页面。


推荐阅读