flutter remove back button on appbar

0 votes

I am wondering, if anyone knows of a way to remove the back button that shows up on the appBar in a flutter app when you use Navigator.pushNamed to go to another page. The reason I do not want it on this resulting page is that it is coming from the navigation and I want users to use the logout button instead, so that the session starts over.

Mar 9 in Android by sarit
• 1,190 points
72 views

1 answer to this question.

0 votes

You can remove the back button from the AppBar in Flutter by setting the AppBar's leading property to null. Here's an example:

AppBar(
  leading: null,
  // other AppBar properties
);

In your case, you can conditionally set the leading property to null based on whether the current page is the resulting page or not. Here's an example:

AppBar(
  leading: Navigator.of(context).canPop() ? null : IconButton(
    icon: Icon(Icons.logout),
    onPressed: () {
      // handle logout
    },
  ),
  // other AppBar properties
);

In this example, the leading property is set to null if the current page can be popped (i.e., there is a previous page on the navigation stack), and it's set to an IconButton with an "logout" icon and a callback that handles the logout if the current page cannot be popped (i.e., it's the resulting page).

answered Mar 10 by vinayak

Related Questions In Android

0 votes
1 answer

How can I remove the debug banner in Flutter?

The debug banner in Flutter can be ...READ MORE

answered Mar 1 in Android by vishalini
66 views
0 votes
1 answer

Create a rounded button / button with border-radius in Flutter

To create a rounded button with border-radius ...READ MORE

answered Mar 1 in Android by vishalini
283 views
0 votes
1 answer

How do I disable a Button in Flutter?

To disable a button in Flutter, you ...READ MORE

answered Mar 10 in Android by vinayak
63 views
0 votes
1 answer
0 votes
1 answer

Can anyone demonstrate how navigation commands can be used on a webpage in Selenium?

Hey Amanprit, Navigation Commands are used to ...READ MORE

answered Jul 5, 2019 in Selenium by Anvi
• 14,170 points
342 views
0 votes
1 answer

What is the future of flutter?

Hi@MD, Flutter is a rather new cross-platform framework ...READ MORE

answered Jul 17, 2020 in Others by akhtar
• 38,240 points
602 views
0 votes
1 answer

What is Flutter?

Hi@akhtar, Flutter is an app SDK for building ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
802 views
0 votes
1 answer

How to change the application launcher icon on Flutter? Ask Question

Yes, you can change the launcher icon ...READ MORE

answered Mar 1 in Android by vishalini
137 views
0 votes
1 answer

Flutter - Wrap text on overflow, like insert ellipsis or fade

Container( padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 18.0), ...READ MORE

answered Mar 1 in Android by vishalini
124 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP