AppBar constructor

const AppBar({
  1. Key? key,
  2. List<Widget> trailing = const [],
  3. List<Widget> leading = const [],
  4. Widget? title,
  5. Widget? header,
  6. Widget? subtitle,
  7. Widget? child,
  8. bool trailingExpanded = false,
  9. AlignmentGeometry alignment = Alignment.center,
  10. EdgeInsetsGeometry? padding,
  11. Color? backgroundColor,
  12. double? leadingGap,
  13. double? trailingGap,
  14. double? height,
  15. double? surfaceBlur,
  16. double? surfaceOpacity,
  17. 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 (List
  • trailing (List
  • title (Widget?, optional): Primary title content
  • header (Widget?, optional): Secondary content above title
  • subtitle (Widget?, optional): Secondary content below title
  • child (Widget?, optional): Custom content (overrides title components)
  • alignment (AlignmentGeometry, default: center): Content alignment
  • trailingExpanded (bool, default: false): Whether trailing area expands
  • useSafeArea (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',
      );