Last updated:
0 purchases
os detect
Platform independent access to information about the current operating system.
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 Platform;
copied to clipboard
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.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.