os_detect 2.0.4
os_detect: ^2.0.4 copied to clipboard
Platform independent OS detection.
Platform independent access to information about the current operating system.
NOTE: This package has been discontinued #
Package os_detect has been discontinued
as package:platform version 3.2 or later now supports similar APIs.
See migration notes below for details.
You can perform an automated migration to package:platform
by running dart fix inside a project that uses the present API.
Migration notes #
The APIs in package:os_detect are top-level getters, typically used like this:
import 'package:os_detect/os_detect.dart' as os_detect;
foo() {
if (os_detect.isAndroid) {
...
}
}
The APIs in package:platform version 3.2 or later,
are instance getters of a Platform object, typically used like this:
import 'package:platform/platform.dart';
foo() {
if (Platform.current.isAndroid) {
...
}
}
Note that operatingSystem and operatingSystemVersion migrate to
NativePlatform.current!.operatingSystem and
NativePlatform.current!.operatingSystemVersion, which are only available on
native platforms (NativePlatform.current is null in a browser). Code that
also runs in a browser should check Platform.current.isBrowser first, or use
BrowserPlatform.current!.version (for example,
NativePlatform.current?.operatingSystemVersion ?? BrowserPlatform.current!.version).
Querying the current OS #
Exposes operatingSystem and operatingSystemVersion strings similar to those
of the Platform class in dart:io, but also works on the web. The
operatingSystem of a browser is the string "browser". Also exposes convenience
getters like isLinux, isAndroid and isBrowser based on the
operatingSystem string.
To use this package instead of dart:io, replace the import of dart:io with:
import 'package:os_detect/os_detect.dart' as os_detect;
That should keep the code working if the only functionality used from dart:io
is operating system detection. You should then use your IDE to rename the import
prefix from Platform to something lower-cased which follows the style guide
for import prefixes.
Any new platform which supports neither dart:io nor dart:html can make
itself recognizable by configuring the dart.os.name and dart.os.version
environment settings, so that const String.fromEnvironment can access them.
Overriding the current OS string #
It's possible to override the current operating system string, as exposed by
operatingSystem and operatingSystemVersion in
package:os_detect/os_detect.dart. To do so, import the
package:os_detect/override.dart library and use the overrideOperatingSystem
function to run code in a zone where the operating system and version values are
set to whatever values are desired.
The class OperatingSystemID can also be used directly to abstract over the
operating system name and version. The OperatingSystemID.current defaults to
the values provided by the platform when not overridden using
overrideOperatingSystem.