maybeWhenConst<R> static method
R
maybeWhenConst<R>({
- required R orElse,
- R? android,
- R? fuchsia,
- R? iOS,
- R? linux,
- R? macOS,
- R? web,
- 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,
};
}