platform_detect 1.2.0

  • README.md
  • Example
  • Installing
  • Versions
  • 38

codecov

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('');
  }
}

example/main.dart

import 'dart:html';
import 'package:platform_detect/src/navigator.dart';
import 'package:platform_detect/src/browser.dart';
import 'package:platform_detect/src/operating_system.dart';
import 'package:platform_detect/platform_detect.dart';

main() {
  _parseCurrentBrowser();
  ButtonElement evaluate = querySelector('#evaluate-test');
  evaluate.onClick.listen((_) => _parseTestValues());
}

void _parseCurrentBrowser() {
  document.querySelector('#current-browser').text = browser.name;
  document.querySelector('#current-vendor').text = window.navigator.vendor;
  document.querySelector('#current-appVersion').text =
      window.navigator.appVersion;
  document.querySelector('#current-appName').text = window.navigator.appName;
  document.querySelector('#current-userAgent').text =
      window.navigator.userAgent;

  CheckboxInputElement isChrome = document.querySelector('#current-is-chrome');
  isChrome.checked = browser.isChrome;

  CheckboxInputElement isFirefox =
      document.querySelector('#current-is-firefox');
  isFirefox.checked = browser.isFirefox;

  CheckboxInputElement isSafari = document.querySelector('#current-is-safari');
  isSafari.checked = browser.isSafari;

  CheckboxInputElement isInternetExplorer =
      document.querySelector('#current-is-ie');
  isInternetExplorer.checked = browser.isInternetExplorer;

  document.querySelector('#current-version').text = browser.version.toString();

  document.querySelector('#current-os').text = operatingSystem.name;
}

void _parseTestValues() {
  InputElement testVendor = querySelector('#test-vendor');
  InputElement testAppVersion = querySelector('#test-appVersion');
  InputElement testAppName = querySelector('#test-appName');
  InputElement testUserAgent = querySelector('#test-userAgent');
  var navigator = new TestNavigator();
  navigator.vendor = testVendor.value.trim();
  navigator.appVersion = testAppVersion.value.trim();
  navigator.appName = testAppName.value.trim();
  navigator.userAgent = testUserAgent.value.trim();
  Browser.navigator = navigator;
  OperatingSystem.navigator = navigator;

  querySelector('#test-browser-name').text = browser.name;
  querySelector('#test-browser-version').text = browser.version.toString();
  querySelector('#test-os-name').text = operatingSystem.name;
}

Use this package as a library

1. Depend on it

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


dependencies:
  platform_detect: ^1.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:platform_detect/platform_detect.dart';
  
Version Uploaded Documentation Archive
1.3.5 Oct 2, 2018 Go to the documentation of platform_detect 1.3.5 Download platform_detect 1.3.5 archive
1.3.4 Jul 31, 2018 Go to the documentation of platform_detect 1.3.4 Download platform_detect 1.3.4 archive
1.3.3 Aug 3, 2017 Go to the documentation of platform_detect 1.3.3 Download platform_detect 1.3.3 archive
1.3.2 May 25, 2017 Go to the documentation of platform_detect 1.3.2 Download platform_detect 1.3.2 archive
1.3.1 Apr 19, 2017 Go to the documentation of platform_detect 1.3.1 Download platform_detect 1.3.1 archive
1.3.0 Apr 12, 2017 Go to the documentation of platform_detect 1.3.0 Download platform_detect 1.3.0 archive
1.2.0 Mar 9, 2017 Go to the documentation of platform_detect 1.2.0 Download platform_detect 1.2.0 archive
1.1.1 Jan 11, 2017 Go to the documentation of platform_detect 1.1.1 Download platform_detect 1.1.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
38
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Running dartdoc failed with the following output:


Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.13.0 <2.0.0