platform library
Properties of the current platform.
The Platform.current object represents the current runtime platform
by having one of Platform.nativePlatform or Platform.browserPlatform
being non-null. Which one is available depends on the runtime system
the current program is running on.
That value can provide more information about the current native or browser platform, respectively.
Example:
import 'platform/platform.dart';
bool get isMobile {
if (Platform.current.nativePlatform case var native?) {
return native.isAndroid || native.isIOS;
}
return false;
}
bool get isWeb => Platform.browserPlatform.current != null;
String get osAndVersionText => switch (Platform.current) {
Platform(nativePlatform: var n?) =>
'${n.operatingSystem} v. ${n.operatingSystemVersion}',
Platform(browserPlatform: var b?) => b.userAgent,
_ => 'Unknown';
}
Note
This library currently provides deprecated legacy LocalPlatform
and FakePlatform classes, and exposes deprecated members on the
Platform interface.
Code using those deprecated members or the class LocalPlatform
should use Platform.nativePlatform or Platform.current instead.
Code using FakePlatform should import package:platform/testing.dart
and use TestNativePlatform instead.
Classes
- BrowserPlatform
- Information about the current browser.
- FakePlatform
- A mutable implementation of the legacy Platform interface.
- LocalPlatform
- NativePlatform
- Properties of the native host platform and process.
- Platform
- Dart runtime platform information.
Extensions
- PlatformIsOS on Platform
- Shorthands for checking operating system on the native platform.