frozenrainyoo / selector

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

selector

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',
);

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');

About

License:MIT License


Languages

Language:Dart 69.2%Language:Ruby 21.6%Language:Swift 6.5%Language:Kotlin 2.1%Language:Objective-C 0.6%