-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[device_info_plus] add toMap #618
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 3.2.0 | ||
|
|
||
| - add `deviceInfo` | ||
|
|
||
| ## 3.1.1 | ||
|
|
||
| - add toMap to WebBrowserInfo | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,15 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
| export 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart' | ||
| show | ||
| AndroidBuildVersion, | ||
| AndroidDeviceInfo, | ||
| BaseDeviceInfo, | ||
| IosDeviceInfo, | ||
| IosUtsname, | ||
| LinuxDeviceInfo, | ||
|
|
@@ -76,4 +79,25 @@ class DeviceInfoPlugin { | |
| /// Returns device information for Windows. | ||
| Future<WindowsDeviceInfo> get windowsInfo async => | ||
| _cachedWindowsDeviceInfo ??= await _platform.windowsInfo()!; | ||
|
|
||
| /// Returns device information for the current platform. | ||
| Future<BaseDeviceInfo> get deviceInfo async { | ||
| if (kIsWeb) { | ||
| return webBrowserInfo; | ||
| } else { | ||
| if (Platform.isAndroid) { | ||
| return androidInfo; | ||
| } else if (Platform.isIOS) { | ||
| return iosInfo; | ||
| } else if (Platform.isLinux) { | ||
| return linuxInfo; | ||
| } else if (Platform.isMacOS) { | ||
| return macOsInfo; | ||
| } else if (Platform.isWindows) { | ||
| return windowsInfo; | ||
| } | ||
| } | ||
|
|
||
| throw UnsupportedError('Unsupported platform'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message probably should tell the user which the current platform is. We could also tell the user to create an issue or PR in this repo for unsupported platforms. Also, does this need tests?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about the idea of more detailed explanation. Most |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 2.3.0 | ||
|
|
||
| - add `BaseDeviceInfo` | ||
|
|
||
| ## 2.2.1 | ||
|
|
||
| - add toMap to WebBrowserInfo | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /// The base class for platform's device info. | ||
| abstract class BaseDeviceInfo { | ||
| /// Serializes device info properties to a map. | ||
| Map<String, dynamic> toMap(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this throw on web?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anymore. There is still a problem with some cached compiler info, you cannot mix web and non-web builds (technically speaking runs, not builds) on a single cache. For example if you do:
$ flutter run --device-id macosthen
$ flutter run --device-id chromefails with a bunch of errors referring not only to
dart:io, but hundreds of errors fordart:ffiandpackage:win32which are transient dependencies fromdevice_info_plus_windows. This is a result of merging #598. To mitigate it you have toflutter cleanevery time you switch running web vs. non-web platforms. When you doflutter build webthis is not a problem, because it uses correct compiler every time it's invoked and does not depend on cached stuff.