Luigi Liberatore
Luigi Liberatore

Reputation: 11

AppBar Leading Customizable?

i need your help because i am customizing my AppBar in flutter and i'd like to know if there is a way to decide what to show on the leading part: in my homepage i'd like to see a logo, but if i navigate to other screens i'd like to see the back button. So my question is: is there a way to write an AppBar class where, maybe with a statement, the device show the logo or the back button(seeing the navigation history)? I hope you understand and thanks.

Upvotes: 1

Views: 1946

Answers (2)

rgisi
rgisi

Reputation: 942

Sure, that's very simple:

In your home screen, pass your logo (can be any Widget) to the AppBar's leading argument. On the other screens, pass nothing and set automaticallyImplyLeading: true - the AppBar will create a back button automatically.

Alternatively, if you only use one AppBar for the whole app, use this snippet:

AppBar(
  leading: ModalRoute.of(context).settings.name == "MY_HOME_SCREEN_ROUTE" ? MyLogoWidget : null,
  automaticallyImplyLeading: true,
  ...
);

Upvotes: 1

Parisa Baastani
Parisa Baastani

Reputation: 1911

I suggest you read this article to have different types of appbar:

https://medium.com/flutter-community/flutter-increase-the-power-of-your-appbar-sliverappbar-c4f67c4e076f

Upvotes: 0

Related Questions