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

Overview

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;

🐞 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

Comments
  • Kind of a bug: analysis_options includes pedantic but pubspec.yaml does not depend on padentic?

    Kind of a bug: analysis_options includes pedantic but pubspec.yaml does not depend on padentic?

    Upon locally cloning and inspecting the repository, I found that the analysis_options.yaml file depends on pedantic's analysis_options.yaml however, there is no such dependency in the top-level pubspec.yaml.

    My text editor (VSCode) gives me a warning about it not finding it.

    Is this absence intentional? Or maybe I'm stupid?

    If not, I can make a PR real quick, if you could give me some pointers. If that's okay?

    Thanks for the package anyhow!

    opened by emme1444 2
  • Cannot run with sound null safety, because the following dependencies

    Cannot run with sound null safety, because the following dependencies

    I get following error when I try to use the package:

    Error: Cannot run with sound null safety, because the following dependencies don't support null safety:

    • package:universal_platform
    opened by syeds-git 1
  • echart not working in web

    echart not working in web

    Hi , i want add san key chart to my project , am using echarts plugin which is working fine in Mobile, in Web its throwing below error

    unsupported operation platform. _operating system flutter

    plugin : https://pub.dev/packages/flutter_echarts

    Is there any other way that i can use san key chart into flutter web

    need your support

    opened by matheshwaran 1
  • Consider dropping flutter dependency

    Consider dropping flutter dependency

    Just a friendly note, that if you don't use flutter and drop dependency on it, the this package will work for dart cli scripts and code generators too..

    https://github.com/gskinnerTeam/flutter-universal-platform/blob/7de13c480b176fd6c83daf2e2c18ea27c82dba4a/pubspec.yaml#L11

    opened by jonasfj 1
  • Add UniversalPlatform.value getter

    Add UniversalPlatform.value getter

    This exposes the current enum value.

    This is useful in order to, for example, switch upon the current platform:

    import 'package:universal_platform/universal_platform.dart';
    
    void main() {
      String platformType;
      switch (UniversalPlatform.value) {
        case UniversalPlatformType.Web:
          platformType = "Web";
          break;
        case UniversalPlatformType.Android:
        case UniversalPlatformType.Fuchsia:
        case UniversalPlatformType.IOS:
          platformType = "Mobile";
          break;
        case UniversalPlatformType.Linux:
        case UniversalPlatformType.MacOS:
        case UniversalPlatformType.Windows:
          platformType = "Desktop";
          break;
      }
    
      print(platformType);
    }
    

    If you want me to add the example somehow, please let me know.

    Thanks!

    opened by emme1444 0
  • Update universal_platform.dart

    Update universal_platform.dart

    added direct checkers for apple device, mobile device and desktop+web OR combinations

    Solve https://github.com/gskinnerTeam/flutter-universal-platform/issues/23 https://github.com/gskinnerTeam/flutter-universal-platform/issues/16

    opened by rsanjuan87 0
  • add isMobile as an alias for isIos || isAndroid

    add isMobile as an alias for isIos || isAndroid

    Adding isMobile as an alias for isIos || isAndroid could make some reading easier.

    I'd gladly submit a PR if I knew it would actually be eventually merged but the repo seems to be stale.

    opened by cedvdb 0
  • The repository is out of sync with pub

    The repository is out of sync with pub

    The repository is out of sync with the version on pub dev..

    I wanted to fix https://github.com/gskinnerTeam/flutter-universal-platform/issues/16 but it's a bit messy to add code that exists already on another commit which is not here

    opened by cedvdb 0
  • Force a platform type when testing

    Force a platform type when testing

    When running tests, either using variant: TargetPlatformVariant.mobile() or debugDefaultTargetPlatformOverride does not cooperate with UniversalPlatform.

    Can you add a method, something like testUniversalPlatformOverride = targetPlatformType to set a platform type for widget testing. Or, perhaps create something that extends from the TestVariant class that could be used.

    opened by martin-robert-fink 1
Owner
gskinner team
We collaborate with smart, motivated clients to conceptualize, design, and build world-class interactive experiences.
gskinner team
Easily build your Widgets, Avoid parenthesis nesting, easy to build UI, A little like swift-ui.

tenon_mortise Easily build your Widgets, Avoid parenthesis nesting, easy to build UI, A little like swift-ui. Getting Started Usage To use this plugin

JieLiu 4 Dec 15, 2022
An intuitive Token Parser that includes grammar definition, tokenization, parsing, syntax error and debugging. Implementation based on Lexical Analysis for Dart.

Token Parser An intuitive Token Parser that includes syntax/grammar definition, tokenization and parsing. Implementation based on Lexical Analysis. Re

JUST A SNIPER ツ 2 Dec 15, 2022
Flutter widget to change `themeMode` during runtime and persist it across restarts.

theme_mode_handler Flutter widget to change themeMode during runtime and persist it across restarts. Motivation Flutter 1.9 introduced a new way to co

Arthur Denner 28 Oct 29, 2022
Widget Runtime for WidgetStudio

flutter_dynamic_widget A Dynamic Widget Runtime from JSON for Flutter Widgets. This package powers https://widget.studio Based on code gen from this p

Rody Davis 61 Dec 6, 2022
Widget that gives you the size of the widget in runtime.

Tailor Flutter widget that calculates the size of a widget in runtime. Usage Just wrap your widget with Tailor and get the size in the builder. The bu

Aman Gupta 7 Nov 2, 2022
🚗 Apple CarPlay for Flutter Apps. Aims to make it safe to use apps made with Flutter in the car by integrating with CarPlay.

CarPlay with Flutter ?? Flutter Apps now on Apple CarPlay! flutter_carplay aims to make it safe to use iPhone apps made with Flutter in the car by int

Oğuzhan Atalay 156 Dec 26, 2022
A platform to make your social media experience more safe

cyber_watch A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

Waleed Umar 0 Feb 25, 2022
Shared preferences typed - A type-safe wrapper around shared preferences, inspired by ts-localstorage

Typed Shared Preferences A type-safe wrapper around shared_preferences, inspired

Philipp Bauer 0 Jan 31, 2022
Toor makes service locators compile-time safe and easy to manage

?? What is Toor Toor makes service locators compile-time safe and easy to manage. ?? Getting Started Define your dependencies somewhere in the project

Arshak Aghakaryan 5 Jul 25, 2022
Safe is an open source mobile platorm to discretely capture incidents with ease, powered by an SMCE written in native Swift and Kotlin.

Safe A powerful tool for personal and community safety. joinsafe.me » Available for iOS & Android ~ Links will be added once a release is available. ~

Safe 10 Oct 26, 2022
This is the code for the POAPin app, which is written in Flutter and currently supports iOS, Android, and Web platforms.

POAPin This is the code for the POAPin app, which is written in Flutter and currently supports iOS, Android, and Web platforms. ?? Get the app Platfor

Glory Lab 17 Nov 7, 2022
A portable canvas that can work in many platforms (Flutter, Web, Desktop, in-memory Image).

pcanvas A portable canvas that can work in many platforms (Flutter, Web, Desktop, in-memory Image). Motivation Canvas operations can be highly depende

Graciliano Monteiro Passos 3 Dec 8, 2022
App HTTP Client is a wrapper around the HTTP library Dio to make network requests and error handling simpler, more predictable, and less verbose.

App HTTP Client App HTTP Client is a wrapper around the HTTP library Dio to make network requests and error handling simpler, more predictable, and le

Joanna May 44 Nov 1, 2022
A package help you to make api call and handle error faster, also you can check for internet before call api.

http_solver ##not for production use, only for learning purpose. A package help you to make api call and handle error faster, also you can check for i

Abdelrahman Saed 1 Jun 18, 2020
20+ Error State For Android and iOS - Flutter

20+ Error State For Android and iOS - Flutter Watch it on YouTube We design 21 error pages for your app it runs both Android and iOS because it builds

Abu Anwar 544 Jan 6, 2023
A collection of stylish animated dialogs like Normal, Progress, Success, Info, Warning, and Error for flutter.

stylish_dialog A collection of stylish animated dialogs like Normal, Progress, Success, Info, Warning, and Error for flutter. Showcase ⭐ Installing de

Marsad Maqsood 5 Nov 8, 2022
A Flutter Material Button that animates between Progress and Error states

progress_button A Material Flutter Button that supports progress and error visuals Getting Started ProgressButton is designed to be easy to use and cu

Halil Ozercan 132 Sep 21, 2022
🧾 Flutter widget allowing easy cache-based data display in a ListView featuring pull-to-refresh and error banners.

Often, apps just display data fetched from some server. This package introduces the concept of fetchable streams. They are just like normal Streams, b

Marcel Garus 17 Jan 18, 2022