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, 2023 in Android by sarit
• 1,830 points
12,074 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).

To know more about Flutter, join our Flutter Certification Course today.

answered Mar 10, 2023 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, 2023 in Android by vishalini
764 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, 2023 in Android by vishalini
31,633 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, 2023 in Android by vinayak
14,761 views
0 votes
1 answer

I am creating mobile application on flutter but facing error of tflite library

The error you're encountering means that there ...READ MORE

answered Mar 18, 2023 in Android by pooja
964 views
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,150 points
655 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,260 points
1,154 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
1,456 views
0 votes
2 answers

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

how to change the app icon in ...READ MORE

answered Nov 29, 2023 in Android by anonymous
10,437 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, 2023 in Android by vishalini
1,333 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