buildByMaterial method
build on material mode
Implementation
@override
Widget buildByMaterial(BuildContext context) {
BaseAppBar? appBar =
valueOf('appBar', this.appBar) ?? valueOf('navBar', navBar);
final double? appBarHeight = BaseTheme.of(context)
.valueOf('appBarHeight', BaseTheme.of(context).appBarHeight);
// Check if drawers are present and automatically inject menu icon if needed
final Widget? drawer = valueOf('drawer', this.drawer);
final Widget? endDrawer = valueOf('endDrawer', this.endDrawer);
// Auto-inject drawer menu icon when drawer is present and no leading widget specified
if (appBar != null &&
drawer != null &&
appBar.leading == null &&
appBar.automaticallyImplyLeading) {
// Create a new BaseAppBar instance with drawer menu icon
appBar = BaseAppBar(
key: appBar.key,
leading: Builder(
builder: (BuildContext context) => IconButton(
icon: const Icon(Icons.menu),
onPressed: () => Scaffold.of(context).openDrawer(),
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
),
),
trailing: appBar.trailing,
automaticallyImplyLeading: appBar.automaticallyImplyLeading,
automaticallyImplyMiddle: appBar.automaticallyImplyMiddle,
backgroundColor: appBar.backgroundColor,
brightness: appBar.brightness,
previousPageTitle: appBar.previousPageTitle,
middle: appBar.middle,
border: appBar.border,
padding: appBar.padding,
transitionBetweenRoutes: appBar.transitionBetweenRoutes,
heroTag: appBar.heroTag,
backdropFilter: appBar.backdropFilter,
height: appBar.height,
title: appBar.title,
actions: appBar.actions,
flexibleSpace: appBar.flexibleSpace,
bottom: appBar.bottom,
elevation: appBar.elevation,
iconTheme: appBar.iconTheme,
shadowColor: appBar.shadowColor,
shape: appBar.shape,
actionsIconTheme: appBar.actionsIconTheme,
textTheme: appBar.textTheme,
primary: appBar.primary,
centerTitle: appBar.centerTitle,
titleSpacing: appBar.titleSpacing,
excludeHeaderSemantics: appBar.excludeHeaderSemantics,
toolbarOpacity: appBar.toolbarOpacity,
bottomOpacity: appBar.bottomOpacity,
foregroundColor: appBar.foregroundColor,
leadingWidth: appBar.leadingWidth,
backwardsCompatibility: appBar.backwardsCompatibility,
toolbarTextStyle: appBar.toolbarTextStyle,
titleTextStyle: appBar.titleTextStyle,
systemOverlayStyle: appBar.systemOverlayStyle,
baseParam: appBar.baseParam,
);
}
Widget? _appBar;
if (appBarHeight != null && appBar != null) {
_appBar = appBar.build(context);
} else {
_appBar = appBar;
}
// Determine if body should extend behind app bar
final bool shouldExtendBehindAppBar =
extendBodyBehindAppBar ?? _shouldExtendBodyBehindAppBar(appBar);
// Intelligent body wrapping with SafeArea
final Widget? bodyWidget = valueOf('body', body);
final Widget? wrappedBody =
bodyWidget != null ? _wrapBodyWithSafeArea(bodyWidget, appBar) : null;
// Get theme-aware background color for Material mode
Color? effectiveBackgroundColor =
valueOf('backgroundColor', backgroundColor);
if (effectiveBackgroundColor == null) {
// Use theme's scaffold background color when no explicit color is provided
effectiveBackgroundColor = Theme.of(context).scaffoldBackgroundColor;
}
return Scaffold(
appBar: _appBar != null ? _appBar as PreferredSizeWidget : null,
body: wrappedBody,
floatingActionButton:
valueOf('floatingActionButton', floatingActionButton),
floatingActionButtonLocation:
valueOf('floatingActionButtonLocation', floatingActionButtonLocation),
floatingActionButtonAnimator:
valueOf('floatingActionButtonAnimator', floatingActionButtonAnimator),
persistentFooterButtons:
valueOf('persistentFooterButtons', persistentFooterButtons),
drawer: valueOf('drawer', drawer),
onDrawerChanged: valueOf('onDrawerChanged', onDrawerChanged),
endDrawer: valueOf('endDrawer', endDrawer),
onEndDrawerChanged: valueOf('onEndDrawerChanged', onEndDrawerChanged),
bottomNavigationBar: valueOf('bottomNavigationBar', bottomNavigationBar),
bottomSheet: valueOf('bottomSheet', bottomSheet),
backgroundColor: effectiveBackgroundColor,
resizeToAvoidBottomInset:
valueOf('resizeToAvoidBottomInset', resizeToAvoidBottomInset),
primary: valueOf('primary', primary),
drawerDragStartBehavior:
valueOf('drawerDragStartBehavior', drawerDragStartBehavior),
extendBody: valueOf('extendBody', extendBody),
extendBodyBehindAppBar: shouldExtendBehindAppBar,
drawerScrimColor: valueOf('drawerScrimColor', drawerScrimColor),
drawerEdgeDragWidth: valueOf('drawerEdgeDragWidth', drawerEdgeDragWidth),
drawerEnableOpenDragGesture:
valueOf('drawerEnableOpenDragGesture', drawerEnableOpenDragGesture),
endDrawerEnableOpenDragGesture: valueOf(
'endDrawerEnableOpenDragGesture', endDrawerEnableOpenDragGesture),
restorationId: valueOf('restorationId', restorationId),
);
}