platform
3.2.0, released 2 months ago by dart.dev
Cross‑platform abstraction for querying runtime platform info in Dart.
WASM-readyRock solid
What it does
Provides a unified API to access native and web platform details, with mock support for tests. It wraps dart:io Platform on native runtimes and exposes browser data on the web.
AI-written summary of version 3.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need to detect OS or browser in a single API
- Require testable platform mocks
- Build apps that run on multiple Dart platforms without conditional imports
Skip it when
- You only target a single platform and want minimal dependencies
- You need advanced device features beyond basic platform info
Strengths
- Simple, zero‑dependency API
- Built‑in test mocking
- Supports all major Dart platforms
- No code generation required
Weaknesses
- Limited to platform info only, no device capabilities
- Requires manual null checks for web vs native
- API changes in 3.2.0 may need migration
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
import 'package:platform/platform.dart';
void main() {
switch (Platform.current) {
case Platform(:var nativePlatform?):
print('Running on ${nativePlatform.operatingSystem} v.${nativePlatform.operatingSystemVersion}');
case Platform(:var browserPlatform?):
print('Running on ${browserPlatform.userAgent}');
}
}Alternatives
Packages that do the same job and could replace platform.
- plugin_platform_interface
Provides a base for platform interfaces but requires custom implementation
50Compare - browser_launcher
Only for web browser detection, not cross‑platform
84Compare
Works with
Packages commonly used together with platform: ones it builds on, ones built on it, and its own family.
- built_valueSame familyImmutable value types with builders, enum classes and JSON serialization for Dart.
- asyncSame familyUtility classes and helpers that extend Dart's async library.
- httpSame familyA composable, Future‑based library for making HTTP requests across platforms.
- matcherSame familySupport for specifying test expectations via an extensible Matcher class.
- intlSame familyA Dart library for internationalization and localization, providing message translation, plural/gender handling, and date/number formatting.
- jniSame familyProvides Dart/Flutter bindings to call native Java code via JNI.
- objective_cSame familySupport library for accessing Objective C via ffigen in Flutter
- mockitoSame familyA mock framework inspired by Mockito with APIs for Fakes, Mocks, behavior verification, and stubbing.