selector 0.2.5 selector: ^0.2.5 copied to clipboard
Multi type supported platform selector to write functional programming.
Selector #
Multi type support Platform Selector
Basic selector #
- with
if
String result = '';
if (Platform.isAndroid) result = 'hello Android';
if (Platform.isIOS) result = 'hello iOS';
if (Platform.isFuchsia) result = 'hello Fuchsia';
if (Platform.isLinux) result = 'hello Linux';
if (Platform.isMacOS) result = 'hello MacOS';
if (Platform.isWindows) result = 'hello Windows';
- with
selector
String result = selector(
android: 'hello Android',
ios: 'hello iOS',
fuchsia: 'hello Fuchsia',
linux: 'hello Linux',
mac: 'hello MacOS',
windows: 'hello Windows',
);
Device selector #
- with
if
String result = '';
if (Platform.isAndroid || Platform.isIOS || Platform.isFuchsia)
result = 'hello Mobile';
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows)
result = 'hello Desktop';
if (kIsWeb) result = 'hello Web';
- with
deviceSelector
String result = deviceSelector(
mobile: 'hello Mobile',
desktop: 'hello Desktop',
web: 'hello Web',
);
OrElse selector #
- with
if
String admobKey;
if (Platform.isAndroid) admobKey = 'android-key';
else admobKey = 'iOS-key';
- with
selector
String admobKey = androidOrElse('android-key', 'iOS-key');
Query #
print('isDesktop: $isDesktop')
print('isMobile: $isMobile')