Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
75 changes: 69 additions & 6 deletions lib/src/interface/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,64 @@ abstract class Platform {
/// 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;

Expand All @@ -20,6 +78,11 @@ abstract class Platform {

/// 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.
Expand All @@ -29,22 +92,22 @@ abstract class Platform {
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.
///
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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

environment:
sdk: '>=2.12.0-0 <3.0.0'

dev_dependencies:
test: ^1.16.0-nullsafety.1
test: ^1.16.8