Add OS constants for use in switch statements (#30)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 558aeb1..664defd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+### 3.0.1
+
+* Added string constants for each of the supported platforms for use in switch
+ statements.
+
### 3.0.0
* First stable null safe release.
diff --git a/lib/src/interface/platform.dart b/lib/src/interface/platform.dart
index 82c8bfe..7f9262f 100644
--- a/lib/src/interface/platform.dart
+++ b/lib/src/interface/platform.dart
@@ -11,6 +11,64 @@
/// Creates a new [Platform].
const Platform();
+ /// A string constant to compare with [operatingSystem] to see if the platform
+ /// is Linux.
+ ///
+ /// Useful in case statements when switching on [operatingSystem].
+ ///
+ /// To just check if the platform is Linux, use [isLinux].
+ static const String linux = 'linux';
+
+ /// A string constant to compare with [operatingSystem] to see if the platform
+ /// is Windows.
+ ///
+ /// Useful in case statements when switching on [operatingSystem].
+ ///
+ /// To just check if the platform is Windows, use [isWindows].
+ static const String windows = 'windows';
+
+ /// A string constant to compare with [operatingSystem] to see if the platform
+ /// is macOS.
+ ///
+ /// Useful in case statements when switching on [operatingSystem].
+ ///
+ /// To just check if the platform is macOS, use [isMacOS].
+ static const String macOS = 'macos';
+
+ /// A string constant to compare with [operatingSystem] to see if the platform
+ /// is Android.
+ ///
+ /// Useful in case statements when switching on [operatingSystem].
+ ///
+ /// To just check if the platform is Android, use [isAndroid].
+ static const String android = 'android';
+
+ /// A string constant to compare with [operatingSystem] to see if the platform
+ /// is iOS.
+ ///
+ /// Useful in case statements when switching on [operatingSystem].
+ ///
+ /// To just check if the platform is iOS, use [isIOS].
+ static const String iOS = 'ios';
+
+ /// A string constant to compare with [operatingSystem] to see if the platform
+ /// is Fuchsia.
+ ///
+ /// Useful in case statements when switching on [operatingSystem].
+ ///
+ /// To just check if the platform is Fuchsia, use [isFuchsia].
+ static const String fuchsia = 'fuchsia';
+
+ /// A list of the possible values that [operatingSystem] can return.
+ static const List<String> operatingSystemValues = <String>[
+ linux,
+ macOS,
+ windows,
+ android,
+ iOS,
+ fuchsia,
+ ];
+
/// The number of processors of the machine.
int get numberOfProcessors;
@@ -20,6 +78,11 @@
/// A string (`linux`, `macos`, `windows`, `android`, `ios`, or `fuchsia`)
/// representing the operating system.
+ ///
+ /// The possible return values are available from [operatingSystemValues], and
+ /// there are constants for each of the platforms to use in switch statements
+ /// or conditionals (See [linux], [macOS], [windows], [android], [iOS], and
+ /// [fuchsia]).
String get operatingSystem;
/// A string representing the version of the operating system or platform.
@@ -29,22 +92,22 @@
String get localHostname;
/// True if the operating system is Linux.
- bool get isLinux => (operatingSystem == "linux");
+ bool get isLinux => operatingSystem == linux;
/// True if the operating system is OS X.
- bool get isMacOS => (operatingSystem == "macos");
+ bool get isMacOS => operatingSystem == macOS;
/// True if the operating system is Windows.
- bool get isWindows => (operatingSystem == "windows");
+ bool get isWindows => operatingSystem == windows;
/// True if the operating system is Android.
- bool get isAndroid => (operatingSystem == "android");
+ bool get isAndroid => operatingSystem == android;
/// True if the operating system is iOS.
- bool get isIOS => (operatingSystem == "ios");
+ bool get isIOS => operatingSystem == iOS;
/// True if the operating system is Fuchsia
- bool get isFuchsia => (operatingSystem == "fuchsia");
+ bool get isFuchsia => operatingSystem == fuchsia;
/// The environment for this process.
///
diff --git a/pubspec.yaml b/pubspec.yaml
index 5480397..480f98e 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: platform
-version: 3.0.0
+version: 3.0.1
description: A pluggable, mockable platform abstraction for Dart.
homepage: https://github.com/google/platform.dart
@@ -7,4 +7,4 @@
sdk: '>=2.12.0-0 <3.0.0'
dev_dependencies:
- test: ^1.16.0-nullsafety.1
+ test: ^1.16.8