universal_platform 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new84

Universal Platform - A Web-safe Platform class #

Currently, if you include the dart.io.Platform anywhere in your code, your 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 #

  universal_platform: ^0.1.3

⚙ 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

0.1.3 #

  • Removed flutter sdk dependency

0.1.2 #

  • Initial version


import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:universal_platform/universal_platform.dart';

void main() => runApp(MaterialApp(home: Demo()));

class Demo extends StatelessWidget {
  Widget build(BuildContext context) {

    return Material(
      child: Center(
          child: Text(
        "Web: ${UniversalPlatform.isWeb} \n "
        "MacOS: ${UniversalPlatform.isMacOS} \n"
        "Windows: ${UniversalPlatform.isWindows} \n"
        "Linux: ${UniversalPlatform.isLinux} \n"
        "Android: ${UniversalPlatform.isAndroid} \n"
        "IOS: ${UniversalPlatform.isIOS} \n"
        "Fuschia: ${UniversalPlatform.isFuchsia} \n",

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  universal_platform: ^0.1.3

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:universal_platform/universal_platform.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-1 points)

19 out of 19 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/src/platform_io.dart.

Run dartfmt to format lib/src/platform_io.dart.

Format lib/universal_platform.dart.

Run dartfmt to format lib/universal_platform.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0-dev <3.0.0