createCupertinoWidget method

  1. @override
Widget createCupertinoWidget(
  1. BuildContext context
)
override

Implementation

@override
Widget createCupertinoWidget(BuildContext context) {
  final data = cupertino?.call(context, platform(context));

  var navigationBar =
      data?.navigationBar ?? appBar?.createCupertinoWidget(context);

  final providerState = PlatformProvider.of(context);
  final useLegacyMaterial =
      providerState?.settings.legacyIosUsesMaterialWidgets ?? false;
  final useMaterial = providerState?.settings.iosUsesMaterialWidgets ?? false;

  Widget result;
  if (bottomNavBar != null) {
    var tabBar =
        data?.bottomTabBar ?? bottomNavBar?.createCupertinoWidget(context);

    //https://docs.flutter.io/flutter/cupertino/CupertinoTabScaffold-class.html
    result = CupertinoTabScaffold(
      key: data?.widgetKey ?? widgetKey,
      backgroundColor: data?.backgroundColorTab,
      resizeToAvoidBottomInset: data?.resizeToAvoidBottomInsetTab ?? true,
      tabBar: tabBar!,
      controller: data?.controller,
      tabBuilder: (BuildContext context, int index) {
        var currentChild = cupertinoTabChildBuilder?.call(context, index) ??
            data?.body ??
            body ??
            SizedBox.shrink();
        return CupertinoPageScaffold(
          // key
          backgroundColor: data?.backgroundColor ?? backgroundColor,
          child: iosContentPad(
            context,
            currentChild.withMaterial(useMaterial),
            navigationBar,
            tabBar,
          ),
          navigationBar: navigationBar,
          resizeToAvoidBottomInset: data?.resizeToAvoidBottomInset ?? true,
          // key: widgetKey used for CupertinoTabScaffold
        );
      },
      restorationId: data?.restorationIdTab,
    );
  } else {
    final child = data?.body ?? body ?? SizedBox.shrink();

    result = CupertinoPageScaffold(
      key: data?.widgetKey ?? widgetKey,
      backgroundColor: data?.backgroundColor ?? backgroundColor,
      child: iosContentPad(
        context,
        child.withMaterial(useMaterial),
        navigationBar,
        null,
      ),
      navigationBar: navigationBar,
      resizeToAvoidBottomInset: data?.resizeToAvoidBottomInset ?? true,
    );
  }

  // Ensure that there is Material widget at the root page level
  // as there can be Material widgets used on ios
  return result.withMaterial(useLegacyMaterial &&
      context.findAncestorWidgetOfExactType<Material>() == null);
}