leading property

Widget? leading
final

A widget to display before the toolbar's title.

Typically the leading widget is an Icon or an IconButton.

Becomes the leading component of the NavigationToolbar built by this widget. The leading widget's width and height are constrained to be no bigger than leadingWidth and toolbarHeight respectively.

If this is null and automaticallyImplyLeading is set to true, the AppBar will imply an appropriate widget. For example, if the AppBar is in a Scaffold that also has a Drawer, the Scaffold will fill this widget with an IconButton that opens the drawer (using Icons.menu). If there's no Drawer and the parent Navigator can go back, the AppBar will use a BackButton that calls Navigator.maybePop.

{@tool snippet}

The following code shows how the drawer button could be manually specified instead of relying on automaticallyImplyLeading:

AppBar(
  leading: Builder(
    builder: (BuildContext context) {
      return IconButton(
        icon: const Icon(Icons.menu),
        onPressed: () { Scaffold.of(context).openDrawer(); },
        tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
      );
    },
  ),
)

{@end-tool}

The Builder is used in this example to ensure that the context refers to that part of the subtree. That way this code snippet can be used even inside the very code that is creating the Scaffold (in which case, without the Builder, the context wouldn't be able to see the Scaffold, since it would refer to an ancestor of that widget).

See also:

Implementation

final Widget? leading;