platformSelect<T> function
- BuildContext context,
- {TargetPlatform renderPlatform,
- @required PlatformBuilder<
T> renderMaterial, - @required PlatformBuilder<
T> renderCupertino, - 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.
Implementation
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) {
case TargetPlatform.android:
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);
default:
throw ArgumentError(
"An unsupported platform of $renderPlatform was specified.");
}
}