platform_detect 1.1.1

  • README.md
  • Example
  • Installing
  • Versions
  • --

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.1.1

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
Awaiting analysis to complete.