AppBar#
AppBar is a built-in widget that provides a material design app bar (also called a toolbar) at the top of your appβs screen. Itβs commonly used inside a Scaffold widget and typically contains elements like a title, navigation icons, actions, and more.
Named Parameters#
AppBar(
leading: β for a widget before the title, often an icon or a back button.
automaticallyImplyLeading: β a boolean to automatically show a leading widget if needed.
title: β the main widget in the app bar, usually text.
actions: β a list of widgets to display in a row after the title.
flexibleSpace: β a widget that fills the app bar behind the title.
bottom: β a PreferredSizeWidget typically used for a tab bar.
elevation: β a double value for the shadow under the app bar.
shadowColor: β the color of the shadow.
surfaceTintColor: β the color that tints the app bar surface.
shape: β a shape for the app barβs material.
backgroundColor: β the background color of the app bar.
foregroundColor: β the color of the app barβs text and icons.
brightness: (deprecated in favor of systemOverlayStyle) β used to control system bar brightness.
iconTheme: β the color and size of the icons.
actionsIconTheme: β the theme for the action icons.
textTheme: (deprecated) β for setting the text theme of the app bar.
toolbarHeight: β a double to set the height of the toolbar.
leadingWidth: β a double to set the width of the leading widget.
toolbarOpacity: β a double for the toolbarβs opacity.
bottomOpacity: β a double for the bottom widgetβs opacity.
toolbarTextStyle: β the text style for the toolbar.
titleTextStyle: β the text style specifically for the title.
systemOverlayStyle: β to control the style of the system status bar.
)
Examples#
β 1. leading:#
Displays a widget before the title (usually an icon or back button).
AppBar(
leading: Icon(Icons.menu),
)
β 2. automaticallyImplyLeading:#
Whether to imply a default leading widget automatically (e.g., back arrow).
AppBar(
automaticallyImplyLeading: false,
)
β 3. title:#
Main widget shown in the middle of the AppBar.
AppBar(
title: Text('My App'),
)
β 4. actions:#
A list of widgets displayed at the end of the AppBar (right side).
AppBar(
actions: [Icon(Icons.search)],
)
β 5. flexibleSpace:#
A widget that appears behind the AppBar (e.g., gradients, images).
AppBar(
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.blue, Colors.green]),
),
),
)
β 6. bottom:#
Widget below the AppBar (commonly used for TabBar).
AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.home)),
Tab(icon: Icon(Icons.settings)),
]),
)
β 7. elevation:#
Z-axis shadow depth below the AppBar.
AppBar(
elevation: 4.0,
)
β 8. shadowColor:#
Color of the AppBarβs shadow.
AppBar(
shadowColor: Colors.red,
)
β 9. surfaceTintColor:#
Color to blend over the AppBarβs surface.
AppBar(
surfaceTintColor: Colors.yellow,
)
β 10. shape:#
Defines a shape for the AppBar.
AppBar(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(bottom: Radius.circular(30)),
),
)
β 11. backgroundColor:#
The background color of the AppBar.
AppBar(
backgroundColor: Colors.purple,
)
β 12. foregroundColor:#
The color for text and icons.
AppBar(
foregroundColor: Colors.white,
)
β 13. iconTheme:#
Theme for icons in the AppBar.
AppBar(
iconTheme: IconThemeData(color: Colors.black),
)
β 14. actionsIconTheme:#
Theme for action icons (right side).
AppBar(
actionsIconTheme: IconThemeData(color: Colors.red),
)
β 15. toolbarHeight:#
Height of the toolbar portion of the AppBar.
AppBar(
toolbarHeight: 80.0,
)
β 16. leadingWidth:#
Width of the leading widget space.
AppBar(
leading: Icon(Icons.menu),
leadingWidth: 100,
)
β 17. toolbarOpacity:#
Opacity of the toolbar section.
AppBar(
toolbarOpacity: 0.8,
)
β 18. bottomOpacity:#
Opacity of the bottom widget (like TabBar).
AppBar(
bottomOpacity: 0.5,
)
β 19. toolbarTextStyle:#
Text style for widgets inside the toolbar (excluding title).
AppBar(
toolbarTextStyle: TextStyle(color: Colors.orange, fontSize: 18),
)
β 20. titleTextStyle:#
Custom text style for the title.
AppBar(
title: Text('Styled Title'),
titleTextStyle: TextStyle(color: Colors.white, fontSize: 22),
)
β 21. systemOverlayStyle:#
Customize the system status bar style (like text color).
AppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
)
β 22. centerTitle:#
Whether to center the title widget.
AppBar(
title: Text('Centered'),
centerTitle: true,
)
β 23. scrolledUnderElevation:#
Elevation when content is scrolled under the AppBar (Material 3).
AppBar(
scrolledUnderElevation: 10.0,
)