platformSelect<T> function

T platformSelect <T>(
  1. BuildContext context,
  2. {TargetPlatform renderPlatform,
  3. @required PlatformBuilder<T> renderMaterial,
  4. @required PlatformBuilder<T> renderCupertino,
  5. PlatformBuilder<T> renderFuchsia}

Allows you to arbitrarily return a value from this method based on the PTheme or renderPlatform specified. It allows you to efficiently choose a widget, property, or object to return based on current platform in a unified way.

renderPlatform is optional, and should be omitted unless needed in rare cases.


T platformSelect<T>(
  BuildContext context, {
  TargetPlatform renderPlatform,
  @required PlatformBuilder<T> renderMaterial,
  @required PlatformBuilder<T> renderCupertino,
  PlatformBuilder<T> renderFuchsia,
}) {
  assert(renderMaterial != null);
  assert(renderCupertino != null);
  final platform = renderPlatform ?? PTheme.of(context).data.platform;
  switch (platform) {
      return renderMaterial(context);
    case TargetPlatform.iOS:
      return renderCupertino(context);
    case TargetPlatform.fuchsia:
      // TODO: fallback on material selection for now.
      return renderFuchsia != null
          ? renderFuchsia(context)
          : renderMaterial(context);
      throw ArgumentError(
          "An unsupported platform of $renderPlatform was specified.");