How to remove back arrow from home screen (flutter)?

Asked

Viewed 448 times

0

People I’m having a problem the moment I logout type, I press the icon to logout it leaves the app, only when soon again it presents an arrow back on the home screen. my code is like this:

  IconButton(
          icon: Icon(Icons.exit_to_app),
          onPressed: (){
            userModel.signOut();
            Navigator.of(context).push(
                MaterialPageRoute(builder: (context)=>LoginScreen())
            );
          },
        ),
  • Take a look here and see if it solves your problem https://stackoverflow.com/questions/44978216/flutter-remove-back-button-appbar#:~:text=9%20Answers&text=You%20can%20remove%20back,back%20to%20the%20%20route earlier.

2 answers

0

AppBar(
      automaticallyImplyLeading: false,
    );

0


Instead of using the method push, that stack a new screen to your list of screens in the application, try using the pushAndRemoveUntil:

IconButton(
          icon: Icon(Icons.exit_to_app),
          onPressed: (){
            userModel.signOut();
            navigator.pushAndRemoveUntil(
                MaterialPageRoute(builder: (context)=>LoginScreen()),
                (Route<dynamic> route) => false,
            );
          },
        ),

This method will remove from the stack (do the pop) from all screens until the second argument returns true. As I put a function that always returns false, it will remove all, to finally bring the next screen.

If you are sure that only one screen existed on your stack, you can also use as suggested in the comments the function pushReplacement. As the name implies, she does the push replacing the position of the current screen:

IconButton(
          icon: Icon(Icons.exit_to_app),
          onPressed: (){
            userModel.signOut();
            navigator.pushReplacement(
                MaterialPageRoute(builder: (context)=>LoginScreen()));
          },
        ),

Browser other questions tagged

You are not signed in. Login or sign up in order to post.