Search code examples
flutterdartflutter-navigation

how to go back to the start point of the app after signing out?


I am trying to go back to my starting point after signing out. I will try to demonstrate my app structure to make it easy for you to understand.

first I have a wrapper

    return user == null ? Authentication() : SectionWrapper();

in the section wrapper, i have 2 routes that I navigate with push replacement

so basically

Authentication() || SectionWrapper() at level 1
  pushReplacement: Section1() || Section2()  

in each of these sections I have 2 buttons and check if user is null, it returns authentication() if not, the section widget. the problem is when i sign out and sign in back again i end up exactly where i signed out, what i want is to go back to auth and when i sign in back again I should move to SectionWrapper(). I tried popUntil but it doesn't work because I am using Push replacement. I also tried Navigator.push to the sectionWrapper() but it has some problem with the uid. Finally, in the section, I tried

user == null
        ? SectionWrapper()
        :Widget tree

but it didn't work

so what are the possible ways of doing so?


Solution

  • You can just push and remove until your main page.

    Navigator.of(context).pushAndRemoveUntil(
                                      MaterialPageRoute(builder: (context) => MainPage()),
                                      (route) => false,
                                    );
    

    then your app will "restart"