maybeWhenConst<R> static method

R maybeWhenConst<R>({
  1. required R orElse,
  2. R? android,
  3. R? fuchsia,
  4. R? iOS,
  5. R? linux,
  6. R? macOS,
  7. R? web,
  8. R? windows,
})

Invokes the given function based on the current platform.

Example usage:

FunctionalPlatform.maybeWhenConst(
  android: () => print('Running on Android'),
  iOS: () => print('Running on iOS'),
  orElse: () => print('Running on other platform'),
);

Implementation

static R maybeWhenConst<R>({
  required R orElse,
  R? android,
  R? fuchsia,
  R? iOS,
  R? linux,
  R? macOS,
  R? web,
  R? windows,
}) {
  if (kIsWeb) return web ?? orElse; // IO is not available on Web.
  switch (defaultTargetPlatform) {
    case TargetPlatform.android:
      return android ?? orElse;
    case TargetPlatform.iOS:
      return iOS ?? orElse;
    case TargetPlatform.macOS:
      return macOS ?? orElse;
    case TargetPlatform.windows:
      return windows ?? orElse;
    case TargetPlatform.linux:
      return linux ?? orElse;
    case TargetPlatform.fuchsia:
      return fuchsia ?? orElse;
  }
}