Skip to content

Commit

Permalink
Added example method
Browse files Browse the repository at this point in the history
  • Loading branch information
vicajilau committed Dec 18, 2024
1 parent 5b29c3a commit f9e1eef
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,21 @@ if (PlatformDetail.isMacOS) {


### 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:
If you need more detailed information about the device and operating system it is running on.
```dart
final descriptionDevice = await PlatformDetail.deviceInfo();
```
Or maybe you need an information string about the device info:
```dart
final descriptionDevice = await PlatformDetail.deviceInfoDetails();
```
This will return something like this:
- 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

### Light/Dark Mode
You can detect too if the device is configured in light or dark mode:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ packages:
path: ".."
relative: true
source: path
version: "4.0.0"
version: "4.1.0"
plugin_platform_interface:
dependency: transitive
description:
Expand Down
42 changes: 26 additions & 16 deletions lib/src/platform_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,22 @@ class PlatformDetail {
/// Check if the platform on which the code is running is macOS.
static bool get isMacOS => defaultTargetPlatform == TargetPlatform.macOS;

/// Fetches detailed device information.
/// The format varies depending on the platform.
/// EXAMPLES:
/// Retrieves detailed device information based on the current platform.
///
/// This method is asynchronous and returns a [BaseDeviceInfo] object containing
/// platform-specific details about the device. Depending on the platform, it will return:
/// 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
/// Fetches detailed device information.
/// The format varies depending on the platform.
///
/// Throws:
/// - An [Exception] if the platform is not recognized or unsupported.
///
/// Returns:
/// - A [Future<String>] with detailed information about the device.
static Future<String> deviceInfoDetails() async {
if (PlatformDetail.isWeb) {
final info = await _deviceInfo.webBrowserInfo;
Expand Down Expand Up @@ -134,17 +139,22 @@ class PlatformDetail {
}
}

/// Fetches detailed device information.
/// The format varies depending on the platform.
/// 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
/// Fetches detailed device information.
/// The format varies depending on the platform.
/// Retrieves detailed device information based on the current platform.
///
/// This method is asynchronous and returns a [BaseDeviceInfo] object containing
/// platform-specific details about the device. Depending on the platform, it will return:
/// - [WebBrowserInfo] for web platforms.
/// - [AndroidDeviceInfo] for Android devices.
/// - [IosDeviceInfo] for iOS devices.
/// - [LinuxDeviceInfo] for Linux systems.
/// - [MacOsDeviceInfo] for macOS systems.
/// - [WindowsDeviceInfo] for Windows systems.
///
/// Throws:
/// - An [Exception] if the platform is not recognized or unsupported.
///
/// Returns:
/// - A [Future<BaseDeviceInfo>] with detailed information about the device.
static Future<BaseDeviceInfo> deviceInfo() async {
if (PlatformDetail.isWeb) {
return await _deviceInfo.webBrowserInfo;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: platform_detail
description: A lightweight library to obtain details of the current platform in a much more complete and simple way.
version: 4.0.0
version: 4.1.0
homepage: https://github.com/vicajilau/platform_detail

environment:
Expand Down

0 comments on commit f9e1eef

Please sign in to comment.