Code Monkey home page Code Monkey logo

platform_detect's Introduction

codecov documentation

platform_detect

A library for detecting browser and platform type and version.

Usage

A simple usage example:

import 'package:platform_detect/platform_detect.dart';

main() {
  if (browser.isChrome) {
	print('thank you for being a friend');
  }

  if (operatingSystem.isMac) {
	print('');
  }
}

Decorating the <html> element with CSS classes

This library can also be used to place CSS classes on the <html> element based on the operating system, browser, or a specific supported feature.

Add the decorator.dart import as shown in the example below, and call decorateRootNodeWithPlatformClasses within main in your application.

import 'package:platform_detect/platform_detect.dart';
import 'package:platform_detect/decorator.dart';

main() {
  decorateRootNodeWithPlatformClasses();
}

The <html> node of your application will now look like something like this:

<html lang="en" class="ua-chrome ua-chrome45 ua-lt-chrome46 ua-lt-chrome47 os-mac no-touch no-mstouch">
  <!-- ... -->
</html>

Feature detection

By default, the only browser feature that the library detects for you is touch / mstouch.

You can extend this functionality to bake in a Modernizr-esque implementation by creating your own Feature instances, and passing a list of them as the features argument to decorateRootNodeWithPlatformClasses:

import 'package:platform_detect/platform_detect.dart';
import 'package:platform_detect/decorator.dart';

// For instance, if you need to detect whether a browser supports H5 canvas stuff...
var canvasFeature = new Feature('canvas', new CanvasElement().context2D != null);

main() {
  // Decorate HTML element
  decorateRootNodeWithPlatformClasses(features: [canvasFeature]);

  // Or use the `isSupported` field somewhere else in your app...
  if (canvasFeature.isSupported) {
    // Do something
  } else {
    // Fall back / warn / etc...
  }
}

The <html> node of your application will now look like something like this for browsers that support canvas:

<html lang="en" class="canvas ...">
  <!-- ... -->
</html>

and something like this for browsers that don't support canvas:

<html lang="en" class="no-canvas ...">
  <!-- ... -->
</html>

platform_detect's People

Contributors

aaronlademann-wf avatar brianblanchard-wf avatar clairesarsam-wf avatar evanweible-wf avatar geethatummala-wf avatar georgelesica-wf avatar greglittlefield-wf avatar jacehensley-wf avatar jamesderlin avatar jayudey-wf avatar joebingham-wk avatar josephswanson-wf avatar mairaemperley-wf avatar markrusciano-wf avatar maxwellpeterson-wf avatar rm-astro-wf avatar rmconsole-readonly-wk avatar rmconsole2-wf avatar rmconsole3-wf avatar rmconsole4-wk avatar rmconsole5-wk avatar rmconsole6-wk avatar rmconsole7-wk avatar robbecker-wf avatar robrbecker avatar sebastianmalysa-wf avatar travissanderson-wf avatar trentgrover-wf avatar tusharmathur-wk avatar wesleybalvanz-wf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

platform_detect's Issues

Bump pub_semver dependency

I think the pub get error message explains this issue best :)

build_runner >=1.12.0 depends on pubspec_parse ^1.0.0 which depends on pub_semver ^2.0.0, build_runner >=1.12.0 requires pub_semver ^2.0.0.
And because platform_detect 1.4.0 depends on pub_semver ^1.4.2 and no versions of platform_detect match >1.4.0 <2.0.0, build_runner >=1.12.0 is incompatible with platform_detect ^1.4.0.

Essentially, pub_semver should be bumped to 2.0.0.

Support Flutter

It would be useful to have Flutter support, i.e. not having to rely on additional imports.

Related is the bug that is caused when the package is currently used in Flutter on mobile: #46

Also, contributing this feature is a recommendation from a Flutter team member: flutter/flutter#58171 (comment)

Support for detecting Android and iOS, and browsers on those platforms

Not sure if this is outside of the scope of this package, but it would be useful for us to detect Android and iOS as platforms, and which browser (Chrome, Safari, Firefox, Samsung's default browser, etc.) is used on those platforms.

For example, iOS doesn't support WebRTC on any other browser than Safari (all other browsers on iOS have to use WebView in their implementations, and it doesn't support WebRTC). So, being able to detect that the platform is iOS, and the browser is not Safari, we could tell the user to use Safari, if WebRTC support is required.

We're currently using a JavaScript library called Bowser, but being able to do these checks in "native" Dart would be very useful.

Add Brave Browser check

Brave Browser uses same name and user agent like Chrome.

Since Brave is quite popular alternative to Chrome, it would be nice to handle that, because even tough, many Web APIs in Brave are restricted (like SpeechRecognition API, thats why I need Your package to check that)

The solution is described below:
(navigator.brave && await navigator.brave.isBrave() || false)
https://www.ctrl.blog/entry/brave-user-agent-detection.html

I found similar package to Your one and created similar issue.

I think good option would be merging You packages into one.

https://github.com/tomaschyly/web_browser_detect

Support for Microsoft Edge

Are there plans to support Edge?

If it is already supported, feel free to close this, but I didn't see Edge in the list of known browsers. Thanks.

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.