AppBar constructor
const
AppBar({
- Key? key,
- List<
Widget> trailing = const [], - List<
Widget> leading = const [], - Widget? title,
- Widget? header,
- Widget? subtitle,
- Widget? child,
- bool trailingExpanded = false,
- AlignmentGeometry alignment = Alignment.center,
- EdgeInsetsGeometry? padding,
- Color? backgroundColor,
- double? leadingGap,
- double? trailingGap,
- double? height,
- double? surfaceBlur,
- double? surfaceOpacity,
- bool useSafeArea = true,
Creates an AppBar with the specified content and configuration.
All parameters are optional with sensible defaults. The app bar automatically handles layout, spacing, and theming while providing extensive customization options for complex interface requirements.
Content can be provided through individual title/header/subtitle parameters
or by using the child parameter for complete custom layouts. Leading
and trailing areas support multiple widgets with automatic spacing.
Parameters:
leading(Listtrailing(Listtitle(Widget?, optional): Primary title contentheader(Widget?, optional): Secondary content above titlesubtitle(Widget?, optional): Secondary content below titlechild(Widget?, optional): Custom content (overrides title components)alignment(AlignmentGeometry, default: center): Content alignmenttrailingExpanded(bool, default: false): Whether trailing area expandsuseSafeArea(bool, default: depends on context): Handle system intrusions
Example:
AppBar(
leading: [BackButton()],
title: Text('Settings'),
trailing: [
IconButton(icon: Icon(Icons.help), onPressed: _showHelp),
PopupMenuButton(items: menuItems),
],
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
)
Implementation
const AppBar({
super.key,
this.trailing = const [],
this.leading = const [],
this.title,
this.header,
this.subtitle,
this.child,
this.trailingExpanded = false,
this.alignment = Alignment.center,
this.padding,
this.backgroundColor,
this.leadingGap,
this.trailingGap,
this.height,
this.surfaceBlur,
this.surfaceOpacity,
this.useSafeArea = true,
}) : assert(
child == null || title == null,
'Cannot provide both child and title',
);