Giter Site home page Giter Site logo

pmg1991 / flutter-universal-platform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jeroen-meijer/flutter-universal-platform

0.0 0.0 0.0 198 KB

A web-safe implementation of dart.io.Platforms. Helps avoid the "Unsupported operation: Platform._operatingSystem" runtime error.

License: MIT License

Kotlin 0.24% Swift 2.28% Objective-C 0.07% Dart 14.23% HTML 2.21% CMake 30.20% C++ 47.96% C 2.80%

flutter-universal-platform's Introduction

Universal Platform - A Web-safe Platform class

pub package likes popularity pub points

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: ^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;

๐Ÿงช Testing

In tests, it's possible to override the current platform to test for different paths of behavior in your production code. You can do so by setting the overrideTestValue to your desired platform.

test('isMobile function works properly', () {
  // Set the override value to simulate a platform.
  UniversalPlatform.overrideTestValue = UniversalPlatformType.MacOS;
  // Don't forget to reset the override value when done.
  addTearDown(UniversalPlatform.clearOverrideTestValue);

  expect(isMobile(), isFalse); // โœ…

  UniversalPlatform.overrideTestValue = UniversalPlatformType.IOS;

  expect(isMobile(), isTrue); // โœ…
});

๐Ÿž 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

flutter-universal-platform's People

Contributors

esdotdev avatar jeroen-meijer avatar bruno-garcia avatar pmg1991 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.