discontinuedPackage os_detect has been discontinued and replaced by platform.

OperatingSystem constructor

  1. @visibleForTesting
OperatingSystem(
  1. String id,
  2. String version
)

Creates a new operating system object for testing.

Can be used with overrideOperatingSystem to selectively change the value returned by current.

Notice: Using this constructor may reduce the efficiency of compilers recognizing code that isn't needed when compiling for a particular platform (aka. "tree-shaking" of unreachable code).

Implementation

// Uses chained conditionals to allow back-ends to constant fold when they
// know what `id` is, which they'd usually know for a specific operation.
// That can avoid retaining *all* the subclasses of `OS`.
@visibleForTesting
@pragma('vm:prefer-inline')
OperatingSystem(String id, String version)
  : this._(
      id == linuxId
          ? const LinuxOS()
          : id == macOSId
          ? const MacOS()
          : id == windowsId
          ? const WindowsOS()
          : id == androidId
          ? const AndroidOS()
          : id == iOSId
          ? const IOS()
          : id == fuchsiaId
          ? const FuchsiaOS()
          : id == browserId
          ? const BrowserOS()
          : UnknownOS(id),
      version,
    );