PlatformDetector class
PlatformDetector Class Documentation:
The PlatformDetector
class is a singleton utility that provides information about the current platform, including type, name, and company.
Example Usage:
// Access the platform information.
PlatformDetector.platform.type; // Returns the current platform type.
PlatformDetector.platform.name; // Returns the current platform name.
PlatformDetector.platform.company; // Returns the current platform company.
// Example of using the `PlatformDetectByType` widget.
PlatformDetectByType(
web: YourWebWidget(),
mobile: YourMobileWidget(),
desktop: YourDesktopWidget(),
)
Class Overview:
- This class is designed to provide a convenient way to access platform-related information.
- It includes methods for detecting the current platform type, name, and company.
- The class is implemented as a singleton to ensure a single instance across the application.
Properties:
- type : Returns the current platform type (
PlatformType
enum). - name : Returns the current platform name (
PlatformName
enum). - company : Returns the current platform company (
PlatformCompany
enum).
Methods:
- detectPlatformsInsideWeb : Detects the platform when running inside a web browser.
- detectPlatforms : Detects the platform when not running inside a web browser.
- byCompany : Returns a value based on the current platform company.
- byName : Returns a value based on the current platform name.
- byType : Returns a value based on the current platform type.
- init : Initializes the platform detection process.
Examples:
// Accessing platform information.
final currentPlatformType = PlatformDetector.platform.type;
final currentPlatformName = PlatformDetector.platform.name;
final currentPlatformCompany = PlatformDetector.platform.company;
// Using the `byCompany` method.
final valueForApple = PlatformDetector.platform.byCompany(apple: "Value for Apple", defaultValue: "Default Value");
// Using the `byName` method.
final valueForAndroid = PlatformDetector.platform.byName(android: "Value for Android", defaultValue: "Default Value");
// Using the `byType` method.
final valueForWeb = PlatformDetector.platform.byType(web: "Value for Web", defaultValue: "Default Value");
Constructors
- PlatformDetector.testableForNonWeb({required TargetPlatform platform})
- PlatformDetector.testableForWeb({required String userAgent})
Properties
- company ↔ PlatformCompany
-
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- name ↔ PlatformName
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- type ↔ PlatformType
-
getter/setter pair
Methods
-
byCompany<
T> ({required T defaultValue, T? apple, T? google, T? linux, T? microsoft}) → T - byCompany Method Documentation :
-
byName<
T> ({required T defaultValue, T? android, T? webAndroid, T? iOS, T? webIOS, T? macOs, T? webMacOs, T? windows, T? webWindows, T? linux, T? webLinux}) → T - byName Method Documentation :
-
byType<
T> ({required T defaultValue, T? web, T? desktop, T? mobile}) → T - byType Method Documentation :
-
detectPlatforms(
TargetPlatform platform) → dynamic - detectPlatforms Method Documentation :
-
detectPlatformsInsideWeb(
String userAgent) → dynamic - detectPlatformsInsideWeb Method Documentation :
-
init(
) → void - init Method Documentation :
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- platform → PlatformDetector
-
no setter