platform_info 3.0.0-nullsafety.0 copy "platform_info: ^3.0.0-nullsafety.0" to clipboard
platform_info: ^3.0.0-nullsafety.0 copied to clipboard

outdated

Contains info about current platform such as Build mode and Operating system

platform_info #

Actions Status Coverage Pub License: WTFPL effective_dart

About #

Cross-platform io/html package.
Works on the web, mobile phones, desktops and console.
Fully caches itself on first initialization.

Easy to use, just add to pubspec.yaml as dependency and then import:
import 'package:platform_info/platform_info.dart';

Platform is a singleton, and the default way to access an instance of Platform is to call static getters:
Platform.instance or Platform.I or platform

Platform Information #

Provides platform information such as:

  • Build mode

    • release
    • profile
    • debug
  • Host platform type

    • io (vm, desktops, mobile, console)
    • web (html, js, browser)
  • Operating system

    • Fuchsia
    • Linux
    • MacOS
    • Windows
    • iOS
    • Android
    • Unknown
  • Version (<unknown> if not available)

  • Locale string (en if not available)

  • The number of individual execution units of the machine (0 if not available)

  • Operating system is known type

  • Is a web-based applications

  • Is a I/O supporting for non-web applications

  • Is a mobile device (Android, iOS)

  • Is a desktop device (Windows, macOS, Fuchsia)

  • Is material design device (Android, Fuchsia)

  • Is cupertino design device (macOS, iOS)

  • isLinux

  • isMacOS

  • isWindows

  • isAndroid

  • isIOS

  • isFuchsia

  • when method allowing to compose a complex condition

platform.when #

Run functions that satisfy the current state of the platform.
You can use nested methods to compose more complex queries.

Operating System

[fuchsia] - whether the operating system is a version of Fuchsia
[windows] - whether the operating system is a version of Windows
[android] - whether the operating system is a version of Android
[iOS] - whether the operating system is a version of iOS
[macOS] - whether the operating system is a version of MacOS
[linux] - whether the operating system is a version of Linux
[unknown] - operating system unknown

Design

[material] - is material (Android, Fuchsia)
[cupertino] - is cupertino (macOS, iOS)

Mobile or desktop

[mobile] - is mobile device (Android, iOS)
[desktop] - is desktop device (Windows, MacOS, Fuchsia)

IO or Web

[web] - is web-based applications
[io] - is I/O supporting for non-web applications

Build mode

[release] - release build mode
[profile] - profile build mode
[debug] - debug build mode
[orElse] - any callback was not called

Sequence of checks
  1. Operating System
  2. Design
  3. Mobile/Desktop
  4. IO/Web
  5. Build mode
  6. Call [orElse] if any callback was not called

For example #

import 'package:platform_info/platform_info.dart';

void main(List<String> args) {
  // Use [Platform.instance] or [Platform.I] or [platform] getter
  print(Platform.instance.version);
  print(Platform.I.operatingSystem);
  print(platform.numberOfProcessors.gcd(1));

  final string = platform.when(
    io: () => platform.when(
      fuchsia:   () => 'io fuchsia',
      windows:   () => 'io windows',
      android:   () => 'io android',
      iOS:       () => 'io iOS',
      macOS:     () => 'io macOS',
      linux:     () => 'io linux',
      unknown:   () => 'io unknown',
    ),
    web: () => platform.when(
      material:  () => 'web Android or Fuchsia',
      cupertino: () => 'web macOS or iOS',
      orElse:    () => 'web Windows or Linux or unknown',
    ),
  );
  print(string);
}

Coverage #

Changelog #

Refer to the Changelog to get all release notes.

Maintainers #

Plague Fox

License #

WTFPL

93
likes
0
pub points
93%
popularity

Publisher

verified publisherplugfox.dev

Contains info about current platform such as Build mode and Operating system

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta

More

Packages that depend on platform_info