This is my participation 8 The fourth of the yuegengwen challenge 8 God , Check out the activity details :8 Yuegengwen challenge
#Platform stay dart:io in , Provide with Platform Class API Parity check , But use instance properties instead of static properties . This difference allows these to be used in the test API, You can provide a simulation implementation in it .
Take a look at the construction method :
class Platform {
static int get numberOfProcessors => _numberOfProcessors;
static String get pathSeparator => _pathSeparator;
static String get localeName => _Platform.localeName();
static String get operatingSystem => _operatingSystem;
static String get operatingSystemVersion => _operatingSystemVersion;
static String get localHostname => _localHostname;
static final bool isLinux = (_operatingSystem == "linux");
static final bool isMacOS = (_operatingSystem == "macos");
static final bool isWindows = (_operatingSystem == "windows");
static final bool isAndroid = (_operatingSystem == "android");
static final bool isIOS = (_operatingSystem == "ios");
static final bool isFuchsia = (_operatingSystem == "fuchsia");
static Map<String, String> get environment => _Platform.environment;
static String get executable => _Platform.executable;
static String get resolvedExecutable => _Platform.resolvedExecutable;
static Uri get script => _Platform.script;
static List<String> get executableArguments => _Platform.executableArguments;
static String get packageRoot => _Platform.packageRoot;
static String get packageConfig => _Platform.packageConfig;
static String get version => _version;
}
Copy code
We can see that there are still many methods , Next, we will mainly introduce the usage method and the meaning of each attribute .
## Usage method
###1. Bring in the package first :
import 'dart:io';
Platform.isAndroid Platform.operatingSystem The use of other attributes is the same as above .
###3 for example :
void _btnPress() {
print(Platform.isAndroid); // true/false
}
Copy code
If your phone is Android , It will print on the console true, Or print it out false.
##API The following is based on Nexus5X API 28 test
table th:second-of-type {width: 100px;}attribute | type | Local printing results | describe |
---|---|---|---|
numberOfProcessors | int | 4 | Number of each execution unit of the machine . |
pathSeparator | String | / | The path separator used by the operating system to separate components in the file path . |
localeName | String | en_US | Gets the name of the current locale . |
operatingSystem | String | android | A string representing the operating system or platform . |
operatingSystemVersion | String | Linux 4.4.124+ #1 SMP PREEMPT Mon Jun 18 17:10:07 UTC 2018 | A string representing the operating system or platform version . |
localHostname | String | localhost | Local host name of the system |
isLinux | bool | false | Whether the operating system is [Linux] Version of |
isMacOS | bool | false | Whether the operating system is [macOS] Version of |
isWindows | bool | false | Whether the operating system is [Windows] Version of |
isAndroid | bool | true | Whether the operating system is [Android] Version of |
isIOS | bool | false | Whether the operating system is [IOS] Version of |
isFuchsia | bool | false | Whether the operating system is [Fuchsia] Version of |
environment | Map< String, String > | {PATH:/sbin:/system/sbin:/system/bin:/s } .. Wait a long string .. | The environment for this process is the mapping from string keys to string values . Mapping is not modifiable , Its contents are retrieved from the operating system on first use .Windows Environment variables on are case insensitive , So in Windows On , Mapping is not case sensitive , And convert all keys to uppercase . On other platforms , You can use case sensitive keys . |
executable | String | /system/bin/app_process32 | The path to the executable used to run the script in this isolation . The text path used to identify the script . This path may be relative , Or just search the system path to find the name of the executable . Use [resolvedExecutable] Get the absolute path of the executable . |
resolvedExecutable | String | /system/bin/app_process32 | After the operating system is parsed , The path to the executable used to run the script in this isolation . This is the absolute path to resolve all symbolic links , Executable file used to run the script . |
script | Uri | file:///main.dart | The absolute number of scripts to run in this quarantine URI. If the executable environment does not support ( Script ),uri It's empty |
executableArguments | List< String > | [] | The flag passed to the executable by running the script in this isolation area . These are the command line flags of the executable before the script name . A new list is provided each time the value is read . |
packageRoot | String | null | --package-root Flag passed to executable , Used to run scripts in this quarantine . without --package-root sign , Then for null |
packageConfig | String | null | --package Flag passed to executable , Used to run scripts in this quarantine . without --package sign , Then for null |
version | String | 2.0.0-dev.58.0.flutter-f981f09760 (Sat May 26 03:16:14 2018 +0000) on "android_ia32" | At present DART The version of the runtime . |