Skip to content

Commit

Permalink
Release 3.2.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
vicajilau committed Aug 6, 2023
1 parent 145aba9 commit 2edd290
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.2.0
* Added productName.
* Updated documentation.
* Upgraded documentation.

## 3.1.0

* Renamed type by currentGroupPlatform
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ and the browser.

The easiest way to use this library is to call the [PlatformDetail][] class as follows.
Multiple instances are not being created since thanks to a factory constructor it always
returns an internal singleton:
returns an internal singleton.

### Detecting by type of platform
If you just need to know if it's mobile, desktop, web, or even desktop/web. You will love:

```dart
import 'package:platform_detail/platform_detail.dart';
Expand All @@ -34,7 +37,7 @@ if (PlatformDetail.isWeb) {
In addition, you can also use the enum in the [PlatformGroup][] to which it belongs. That is, if it is web, mobile or desktop:

```dart
switch (PlatformDetails.type) {
switch (PlatformDetails.currentGroupPlatform) {
case PlatformGroup.mobile:
print('The current group platform is mobile');
break;
Expand All @@ -47,6 +50,7 @@ switch (PlatformDetails.type) {
}
```

### Detecting by single platform
If instead you want to ask individually for each platform supported by Flutter:

```dart
Expand Down Expand Up @@ -74,6 +78,15 @@ if (PlatformDetail.isMacOS) {
print('The current platform is macOS');
}
```


### Get a device description
If you need more detailed information about the device and operating system it is running on. In web you will get information from the browser:
```dart
final descriptionDevice = await PlatformDetail.productName;
```

### Light/Dark Mode
You can detect too if the device is configured in light or dark mode:

```dart
Expand Down
51 changes: 51 additions & 0 deletions lib/src/platform_detail.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';

Expand Down Expand Up @@ -92,3 +93,53 @@ class PlatformDetail {
static DeviceTheme get theme =>
isLightMode ? DeviceTheme.light : DeviceTheme.dark;
}

extension DevicesName on PlatformDetail {
/// This parameter returns the industrial name and OS version of the current device.
/// EXAMPLES:
/// Android: Android 9 (SDK 28), Xiaomi Redmi Note 7
/// iOS: iOS 13.1, iPhone 11 Pro Max iPhone
/// Web: Google Chrome (115.0.5790.170)
/// Linux: Fedora 17 (Beefy Miracle)
/// Windows: Windows 10 Home (1903)
/// MacOS: macOS 13.5, MacBook Pro
static Future<String> get productName async {
if (PlatformDetail.isWeb) {
final info = await DeviceInfoPlugin().webBrowserInfo;
return '${info.browserName.name} (${info.appVersion})';
}

switch (PlatformDetail.currentPlatform) {
case TargetPlatform.android:
final androidInfo = await DeviceInfoPlugin().androidInfo;
final release = androidInfo.version.release;
final sdkInt = androidInfo.version.sdkInt;
final manufacturer = androidInfo.manufacturer;
final model = androidInfo.model;
return 'Android $release (SDK $sdkInt), $manufacturer $model';
case TargetPlatform.fuchsia:
final fuchsiaInfo = await DeviceInfoPlugin().androidInfo;
final release = fuchsiaInfo.version.release;
final sdkInt = fuchsiaInfo.version.sdkInt;
final manufacturer = fuchsiaInfo.manufacturer;
final model = fuchsiaInfo.model;
return 'Fuchsia $release (SDK $sdkInt), $manufacturer $model';
case TargetPlatform.iOS:
var iosInfo = await DeviceInfoPlugin().iosInfo;
var systemName = iosInfo.systemName;
var version = iosInfo.systemVersion;
var name = iosInfo.name;
var model = iosInfo.model;
return '$systemName $version, $name $model';
case TargetPlatform.linux:
final info = await DeviceInfoPlugin().linuxInfo;
return info.prettyName;
case TargetPlatform.macOS:
final info = await DeviceInfoPlugin().macOsInfo;
return "macOS ${info.osRelease}, ${info.model}";
case TargetPlatform.windows:
final info = await DeviceInfoPlugin().windowsInfo;
return "${info.productName}(${info.releaseId})";
}
}
}
63 changes: 62 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.17.1"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
sha256: "86add5ef97215562d2e090535b0a16f197902b10c369c558a100e74ea06e8659"
url: "https://pub.dev"
source: hosted
version: "9.0.3"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64
url: "https://pub.dev"
source: hosted
version: "7.0.0"
fake_async:
dependency: transitive
description:
Expand All @@ -49,6 +65,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
sha256: ed5337a5660c506388a9f012be0288fb38b49020ce2b45fe1f8b8323fe429f99
url: "https://pub.dev"
source: hosted
version: "2.0.2"
file:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -67,6 +99,11 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -115,6 +152,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.3"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "43798d895c929056255600343db8f049921cbec94d31ec87f1dc5c16c01935dd"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -176,6 +221,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
win32:
dependency: transitive
description:
name: win32
sha256: f2add6fa510d3ae152903412227bda57d0d5a8da61d2c39c1fb022c9429a41c0
url: "https://pub.dev"
source: hosted
version: "5.0.6"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: e4506d60b7244251bc59df15656a3093501c37fb5af02105a944d73eb95be4c9
url: "https://pub.dev"
source: hosted
version: "1.1.1"
sdks:
dart: ">=3.0.0 <4.0.0"
flutter: ">=1.17.0"
flutter: ">=3.3.0"
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: platform_detail
description: A lightweight library to obtain details of the current platform in a much more complete and simple way.
version: 3.1.0
version: 3.2.0
homepage: https://github.com/vicajilau/platform_detail

environment:
sdk: '>=3.0.0 <4.0.0'
flutter: ">=1.17.0"

dependencies:
device_info_plus: ^9.0.3
flutter:
sdk: flutter

Expand Down

0 comments on commit 2edd290

Please sign in to comment.