From f9e1eefefa448d4e5c257754d35a2791c810038e Mon Sep 17 00:00:00 2001 From: Victor Carreras <34163765+vicajilau@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:38:16 +0100 Subject: [PATCH] Added example method --- README.md | 13 ++++++++++- example/pubspec.lock | 2 +- lib/src/platform_detail.dart | 42 ++++++++++++++++++++++-------------- pubspec.yaml | 2 +- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d472b74..e392253 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/example/pubspec.lock b/example/pubspec.lock index f5b61e9..f3a4be9 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -182,7 +182,7 @@ packages: path: ".." relative: true source: path - version: "4.0.0" + version: "4.1.0" plugin_platform_interface: dependency: transitive description: diff --git a/lib/src/platform_detail.dart b/lib/src/platform_detail.dart index 26c02e9..c557153 100644 --- a/lib/src/platform_detail.dart +++ b/lib/src/platform_detail.dart @@ -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] with detailed information about the device. static Future deviceInfoDetails() async { if (PlatformDetail.isWeb) { final info = await _deviceInfo.webBrowserInfo; @@ -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] with detailed information about the device. static Future deviceInfo() async { if (PlatformDetail.isWeb) { return await _deviceInfo.webBrowserInfo; diff --git a/pubspec.yaml b/pubspec.yaml index 98451d9..2e7d8ce 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: