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: 'Running on Android',
  iOS: 'Running on iOS',
  orElse: '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.

  return switch (defaultTargetPlatform) {
    TargetPlatform.android => android ?? orElse,
    TargetPlatform.iOS => iOS ?? orElse,
    TargetPlatform.macOS => macOS ?? orElse,
    TargetPlatform.windows => windows ?? orElse,
    TargetPlatform.linux => linux ?? orElse,
    TargetPlatform.fuchsia => fuchsia ?? orElse,
  };
}