forked from dart-archive/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Create migration-guide.md #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Migration guide | ||
|
||
This migration guide details how to migrate from from earlier Dart platform APIs | ||
in `package:platform` version 3.x to, and in `dart:io`, to `package:platform` | ||
version 4.x. | ||
|
||
## From `package:platform` version 3.x | ||
|
||
### General platform APIs | ||
|
||
The general APIs in `package:platform` v3.x, that determine what the host | ||
platform is, rely on instantiating an instance of the `LocalPlatform` class. In | ||
v4.0 a new convenience `.current` getter can be used, which returns the current | ||
host platform. | ||
|
||
Migrate from: | ||
```dart | ||
import 'package:platform/platform.dart'; // version 3.x | ||
|
||
bool onAndroid = LocalPlatform().isAndroid; | ||
``` | ||
|
||
To: | ||
```dart | ||
import 'package:platform/host.dart'; // version 4.x | ||
|
||
bool onAndroid = HostPlatform.current.isAndroid; | ||
``` | ||
|
||
### Native-only | ||
|
||
APIs in `package:platform` which are available only on native platforms (and not, | ||
for example, on the web) have been moved to a separate library, | ||
`package:platform/native.dart`. | ||
|
||
Migrate from: | ||
```dart | ||
import 'package:platform/platform.dart'; // version 3.x | ||
|
||
String hostname = LocalPlatform().localHostname; | ||
``` | ||
|
||
To: | ||
```dart | ||
import 'package:platform/native.dart'; // version 4.x | ||
|
||
String hostName = NativePlatform.current.localHostname; | ||
``` | ||
|
||
## From `dart:io` | ||
|
||
The `dart:io` core library is only available on Dart native platforms | ||
(and, for example, not available on Dart web platforms). | ||
We recommend migration to `package:platform` version 4.x, as the APIs in | ||
`package:platform/platform.dart` are available on all current platforms. For the | ||
additional native-only APIs, those available in `package:platform/native.dart`. | ||
|
||
### General platform APIs | ||
|
||
The `dart:io` library exposes host platform information as static members of the | ||
`Platform` class. This API has historically been made available on some | ||
platforms that don't otherwise support `dart:io`. | ||
|
||
To migrate uses of that API to `package:platform` v4.x, use the similarly-named | ||
members on the `HostPlatform.current` object. | ||
|
||
Migrate from: | ||
```dart | ||
import 'dart:io'; | ||
|
||
bool onAndroid = Platform.isAndroid; | ||
``` | ||
|
||
To: | ||
```dart | ||
import 'package:platform/host.dart'; // version 4.x | ||
|
||
bool onAndroid = HostPlatform.current.isAndroid; | ||
``` | ||
|
||
### Native-only | ||
|
||
The remaining `dart:io` APIs on the `Platform` class, have never worked on | ||
non-native platforms. To migrate uses of those to `package:platform` v4.x, use | ||
the similarly named members of the `NativePlatform.current` object from the | ||
`package:platform/native.dart`. | ||
|
||
The native APIs in `dart:io` are accessed via static methods on the `Platform` | ||
class. To migrate to `package:platform` v4.x, use the similar methods on | ||
instance returned via the `NativePlatform.current` getter. | ||
|
||
Migrate from: | ||
```dart | ||
import 'dart:io'; | ||
|
||
String hostname = Platform.localHostname; | ||
``` | ||
|
||
To: | ||
```dart | ||
import 'package:platform/native.dart'; // version 4.x | ||
|
||
String hostName = NativePlatform.current.localHostname; | ||
``` | ||
|
||
## From package:os_detect | ||
|
||
## General platform APIs | ||
|
||
Migrate from: | ||
```dart | ||
import 'package:os_detect/os_detect.dart' as Platform; | ||
|
||
bool onAndroid = Platform.isAndroid; | ||
``` | ||
|
||
To: | ||
```dart | ||
import 'package:platform/host.dart'; // version 4.x | ||
|
||
bool onAndroid = HostPlatform.current.isAndroid; | ||
``` | ||
|
||
### Native-only | ||
|
||
`package:os_detect` has no native-only APIs. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.