buildByCupertino method
build on cupertino mode (Flutter implementation)
Implementation
@override
Widget buildByCupertino(BuildContext context) {
// Check if drawers are present - if so, automatically use Material design
// This ensures Scaffold.of(context).openDrawer() works without manual forceUseMaterial
final Widget? drawer = valueOf('drawer', this.drawer);
final Widget? endDrawer = valueOf('endDrawer', this.endDrawer);
final Widget? fab =
valueOf('floatingActionButton', this.floatingActionButton);
if (drawer != null || endDrawer != null || fab != null) {
// Automatically use Material design when drawers or FAB are present
// This provides the proper Scaffold context for these Material-only features
return buildByMaterial(context);
}
final Widget body = valueOf('body', this.body);
assert(body != null, 'body can\'t be null');
final Color? backgroundColor =
valueOf('backgroundColor', this.backgroundColor);
final BaseAppBar? appBar =
valueOf('appBar', this.appBar) ?? valueOf('navBar', navBar);
final double? appBarHeight = BaseTheme.of(context)
.valueOf('appBarHeight', BaseTheme.of(context).appBarHeight);
Widget? navigationBar;
if (appBarHeight != null && appBar != null) {
navigationBar = appBar.build(context);
} else {
navigationBar = appBar;
}
// Type-safe navigation bar assignment
// If the navigation bar is not an ObstructingPreferredSizeWidget (e.g., BaseAppBar forced to Material mode),
// automatically fall back to using Material's Scaffold to display it properly
if (navigationBar != null &&
navigationBar is! ObstructingPreferredSizeWidget) {
// Navigation bar is not compatible with CupertinoPageScaffold
// Switch to Material Scaffold to display it properly
return buildByMaterial(context);
}
ObstructingPreferredSizeWidget? cupertinoNavigationBar;
if (navigationBar != null &&
navigationBar is ObstructingPreferredSizeWidget) {
cupertinoNavigationBar = navigationBar;
}
// Intelligent body wrapping with SafeArea
final Widget _child = _wrapBodyWithSafeArea(body, appBar);
return CupertinoPageScaffold(
navigationBar: cupertinoNavigationBar,
backgroundColor: backgroundColor,
resizeToAvoidBottomInset:
valueOf('resizeToAvoidBottomInset', resizeToAvoidBottomInset),
child: _child,
);
}