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);
}
You should as the following:
onPressed: () {
FirebaseAuth auth = FirebaseAuth.instance;
auth.signOut().then((res) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => SignIn()),
);
});
},
Here onPressed
of the signOut
button, the user signs out of firebase thus there will be no current user and you will navigate to a different page.