p-hatan/ mirror

pub repository

mirror.p-hatan.com

platform

3.2.0

A pluggable, mockable platform information abstraction for Dart.

Cached in Iran · Upstream SHA-256 matched

Download archive

Readme

Pub

A generic platform abstraction for Dart.

Cross-platform platform API

Provides access to platform specific information of the current runtime platform through a cross-platform API.

On a native platform, the NativePlatform class in this package provides a lightweight wrapper around the static Platform properties of dart:io, with the same rich, Dart-idiomatic API for querying the current runtime.

On the web, there is no NativePlatform object, and cross-platform client code can avoid dependencies on such properties simply by checking if Platform.current.nativePlatform is null. Instead web code has a Platform.current.browserPlatform values that is a non-null BrowserPlatform.

Example:

import 'package:platform/platform.dart';

void main() {
  switch (Platform.current) {
    case Platform(:var nativePlatform?):
      // `nativePlatform` has `dart:io`'s `Platform` properties.
      print(
        'Running on ${nativePlatform.operatingSystem} v.'
        '${nativePlatform.operatingSystemVersion}',
      );
    case Platform(:var browserPlatform?):
      // `browserPlatform` has version information from `windows.userAgent`.
      print('Running on ${browserPlatform.userAgent}');
  }
}

Code size

Using platform-specific properties like Platform.isLinux as branch conditions will allow a production compiler to completely omit the branch that it knows it's not currently compiling for.

Testing and Mocking

In tests, the package:platform/testing.dart library provides ways to mock platform objects with custom tailored configurations, and allows Zone based overriding of the Platform.current value.

[!NOTE] The testing library should only be used in tests, since its mere presence may affect how much code a compiled program will retain.

Changelog

3.2.0

  • New non-backwards compatible API. Use Platform.current to access the current platform, and Platform.current.nativePlatform to either get access to native platform information, or get a null on non-native platforms. Similarly Platform.current.browserPlatform is only non-null on the web.

    Mocking APIs are moved to a separate library to ensure they are only used for testing, and to allow better performance in production.

    Legacy APIs are deprecated, but retained and emulated using the new API. Use dart fix to migrate off the deprecated API.

3.1.6

  • Move to dart-lang/core monorepo.

3.1.5

3.1.4

  • Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
  • Fixes new lint warnings.

3.1.3

  • Adds example app.

3.1.2

  • Adds pub topics to package metadata.
  • Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.

3.1.1

3.1.0

  • Removed Platform.packageRoot, which was already marked deprecated, and which didn't work in Dart 2.

3.0.2

  • Added FakePlatform.copyWith function.

3.0.1

  • Added string constants for each of the supported platforms for use in switch statements.

3.0.0

  • First stable null safe release.

3.0.0-nullsafety.4

  • Update supported SDK range.

3.0.0-nullsafety.3

  • Update supported SDK range.

3.0.0-nullsafety.2

  • Update supported SDK range.

3.0.0-nullsafety.1

  • Migrate package to null-safe dart.

2.2.1

  • Add operatingSystemVersion

2.2.0

  • Declare compatibility with Dart 2 stable
  • Update dependency on package:test to 1.0

2.1.2

  • Relax sdk upper bound constraint to '<2.0.0' to allow 'edge' dart sdk use.

2.1.1

  • Bumped maximum Dart SDK version to 2.0.0-dev.infinity

2.1.0

  • Added localeName
  • Bumped minimum Dart SDK version to 1.24.0-dev.0.0

2.0.0

  • Added stdinSupportsAnsi and stdinSupportsAnsi
  • Removed ansiSupported

1.1.1

  • Updated LocalPlatform to use new dart.io API for ansi color support queries
  • Bumped minimum Dart SDK version to 1.23.0-dev.10.0

1.1.0

  • Added ansiSupported
  • Bumped minimum Dart SDK version to 1.23.0-dev.9.0

1.0.2

  • Minor doc updates

1.0.1

  • Added const constructors for Platform and LocalPlatform

1.0.0

  • Initial version

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add platform
pubspec.yaml
name: platform
description: A pluggable, mockable platform information abstraction for Dart.
repository: https://github.com/dart-lang/core/tree/main/pkgs/platform
issue_tracker: https://github.com/dart-lang/core/issues
version: 3.2.0

environment:
  # IF UPDATED: Also update SDK version in pubspecs in `example/` and `out/`.
  sdk: ^3.10.0

dependencies:
  meta: ^1.18.0

dev_dependencies:
  dart_flutter_team_lints: ^3.5.2
  path: ^1.9.1
  test: ^1.29.0
topics:
  - information
  - platform

Version history

VersionPublishedArchiveSHA-256
1.0.02017-01-25T20:25:16.190ZCached006287698ad85b5a624136239f5f54d68038ba8fa7dd27511efc281257be5428
1.0.12017-01-25T21:45:15.112ZCachedacd56d150362e22485d08ef29428c01129aa890e9330d282bd934e64dda1f304
1.0.22017-02-13T18:45:49.417ZCached632db12927a94b7dd902457d1c8513372db97ca9d5dc8cfa9a94b7703c834563
1.1.02017-03-16T23:34:57.669ZCached498a07d39b5a43c7201333631f20287130424c733c3ff01e88a72db0eadfa761
1.1.12017-03-28T21:24:49.422740ZCached7b3cdde106de8ebf252e9df022a1332bca44159fcf98ea604b264d978b753181
2.0.02017-04-05T21:30:18.567199ZCached644b8a034cadf8cefccda87261c84126bde38d88330bbf98e6c2bcb5dcd209f5
2.1.02017-05-19T16:23:23.730427ZCached02a838c23e46dad51cc3b1c99a2010443976771b5e62ae368400bcb24a14dcd1
2.1.12017-07-13T18:35:38.355065ZCachedb83564875c402d68ff08fd928965b40f86072a7cf265dab3f36785c0cf253abd
2.1.22018-02-12T18:37:53.523631ZCached9407299b24973da333ef09f0c2b8fe7e69dadea609a04767ac34eb9e9c29b807
2.2.02018-08-13T18:06:22.704670ZCached02f0d0a773d3911de89cf764067dc8609444890795b92f6b4fdc8098f260157c
2.2.12019-07-29T02:17:26.407407ZCached2d03e4330ae22fc7fc0dd38c1fc6d0a9dc7ff10d7deea6dbb2583f7e5c053453
3.0.0-nullsafety.12020-08-10T23:57:46.803106ZCached90cf39685bcb3ce2ad4d1774522d4532869de69e85191bee8c9f44e1f710f7d0
3.0.0-nullsafety.22020-09-22T20:43:12.031743ZCached388a484c298dc3dd52a09de759902e18da77a2c96309006b32ff1e47356f2be9
3.0.0-nullsafety.32020-10-22T17:06:57.682021ZCached6dcfb8c1c784629592ec6b081de6d490f97640c941287e77bcaa1e3103b55105
3.0.0-nullsafety.42020-11-04T18:29:51.816242ZCachede4740b21ec2d819d4e157c9b932984d0ca6bd08d83a0c25f9f27818f4d6d9116
3.0.02021-02-03T17:44:42.375849ZCachedebc79f16b5f6b609aad4a5e63447d4795d16f7adee46e93ed03200848c006735
3.0.22021-08-17T01:11:21.745994ZCached4a8c298d9ac37f18a1116f7be2aa86c3eaea5913586c5afbb905429dd79efa84
3.1.02021-12-02T18:13:18.204487ZCached4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76
3.1.12023-08-16T17:48:59.600563ZCached57c07bf82207aee366dfaa3867b3164e4f03a238a461a11b0e8a3a510d51203d
3.1.22023-08-30T15:06:13.346585ZCachedae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102
3.1.32023-10-09T15:45:54.213327ZCached0a279f0707af40c890e80b1e9df8bb761694c074ba7e1d4ab1bc4b728e200b59
3.1.42024-01-04T03:51:45.541663ZCached12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec
3.1.52024-06-10T14:23:19.025398ZCached9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65
3.1.62024-10-17T11:43:56.147795ZCached5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984
3.2.02026-09-07T11:16:26.455977ZCacheda36d119c13416516a7b5913fbe8af8531e11633d784c550b2125f76c758524ec

Dependencies

meta "^1.18.0"