Skip to content
pubscout

platform

3.2.0, released 2 months ago by dart.dev

Cross‑platform abstraction for querying runtime platform info in Dart.

WASM-readyRock solid
$ flutter pub add platform
Source repository

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.

Works with

Packages commonly used together with platform: ones it builds on, ones built on it, and its own family.