Search packages, repositories and app categories

Package detailsv1.1.0

universal_platform

Replacement for dart.io.Platform class which works on Web as well as Desktop and Mobile. Allows platform checks in your view/model layer easily.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
1.8M
Likes
313
Pub points
150

Install package

flutter pub add universal_platform

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The universal_platform package provides a cross-platform replacement for Dart's Platform class, enabling consistent platform detection across Web, mobile, and desktop environments. It allows developers to perform platform checks in business logic layers (like views and models) without relying on platform-specific implementations. This ensures reliable behavior regardless of the target runtime, simplifying code that needs to adapt based on the underlying platform.

Use cases

  • Cross-platform app development
  • Platform-specific UI/behavior logic
  • Shared business logic across platforms
  • Testing on multiple targets
  • Avoiding platform-specific imports

Key features

  • Unified platform detection
  • Works on Web, Android, iOS, macOS, Windows, Linux
  • No need for conditional imports
  • Simple API similar to dart:io.Platform
  • Supports isAndroid, isIOS, isWeb, etc.

Suitable for

  • Developers targeting multiple platforms
  • Apps requiring consistent platform checks
  • Teams avoiding platform-specific code duplication
  • Projects using shared logic across platforms
  • Those needing reliable web support

Considerations

  • Requires explicit import instead of dart:io.Platform
  • May not cover all niche platform features
  • Limited to basic platform identification
  • Not a full replacement for all dart:io functionality
  • Depends on external dependency management

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Universal Platform - A Web-safe Platform class

pub package

Currently, if you include the dart.io.Platform anywhere in your code, your app will throw the following error on Web:

Unsupported operation: Platform._operatingSystem

With this plugin you can perform platform detection on all platforms, including Web, without errors.

🔨 Installation

dependencies:
  universal_platform: ^1.0.0+1
⚙ Import

Remove any usages of dart.io.Platform, and replace with this:

import 'package:universal_platform/universal_platform.dart';

🕹️ Usage

This acts as a drop-in replacement for dart.io.Platform, with a different name for improved clarity.

//This will explode on Web
bool isIos = Platform.isIOS;

//This will not :)
bool isIos = UniversalPlatform.isIOS;
bool isWeb = UniversalPlatform.isWeb;

🐞 Bugs/Requests

If you encounter any problems feel open an issue. If you feel the library is missing a feature, please raise a ticket on Github and we'll look into it. Pull request are also welcome.

📃 License

MIT License

Categories

Source repository

Projects using this package