platformWrap<T extends Widget> function

T platformWrap <T extends Widget>(
  1. BuildContext context,
  2. {@required T child,
  3. TargetPlatform renderPlatform,
  4. ChildPlatformBuilder<T> renderMaterial,
  5. ChildPlatformBuilder<T> renderCupertino,
  6. ChildPlatformBuilder<T> renderFuchsia}
)

Similiar to platformSelect except it provides a way to wrap the passed child on a certain platform while enabling on other platforms simply returning the child.

renderPlatform is optional and should be omitted except in rare cases.

Implementation

T platformWrap<T extends Widget>(
  BuildContext context, {
  @required T child,
  TargetPlatform renderPlatform,
  ChildPlatformBuilder<T> renderMaterial,
  ChildPlatformBuilder<T> renderCupertino,
  ChildPlatformBuilder<T> renderFuchsia,
}) {
  final platform = renderPlatform ?? PTheme.of(context).data.platform;
  switch (platform) {
    case TargetPlatform.android:
      return renderMaterial != null ? renderMaterial(context, child) : child;
    case TargetPlatform.iOS:
      return renderCupertino != null ? renderCupertino(context, child) : child;
    case TargetPlatform.fuchsia:
      // TODO: fallback on material selection for now.
      return renderFuchsia != null
          ? renderFuchsia(context, child)
          : renderMaterial != null ? renderMaterial(context, child) : child;
    default:
      return child;
  }
}