detectPlatforms method
detectPlatforms Method Documentation :
The detectPlatforms
function , is called when the code is not running on the web and is a utility for detecting the current platform and populating platform-related information.
Usage:
PlatformType type;
PlatformName name;
PlatformCompany company;
detectPlatforms();
// Now 'type', 'name', and 'company' hold information about the current platform.
print('Platform Type: $type');
print('Platform Name: $name');
print('Platform Company: $company');
Overview:
- This utility function detects the current platform (mobile, desktop) and populates platform-related information.
Detection Process:
- It uses
defaultTargetPlatform
to determine the current platform. - Based on the detected platform, it sets the values for
type
,name
, andcompany
.
Supported Platforms:
- Mobile Platforms: iOS, Android
- Desktop Platforms: macOS, Windows, Linux
Platform Type Enumeration:
- PlatformType.mobile : Represents mobile platforms.
- PlatformType.desktop : Represents desktop platforms.
Platform Name Enumeration:
- PlatformName.iOS : iOS platform.
- PlatformName.android : Android platform.
- PlatformName.macOs : macOS platform.
- PlatformName.windows : Windows platform.
- PlatformName.linux : Linux platform.
Platform Company Enumeration:
- PlatformCompany.apple : Apple Inc.
- PlatformCompany.google : Google LLC.
- PlatformCompany.microsoft : Microsoft Corporation.
- PlatformCompany.linux : Linux Community.
Implementation
detectPlatforms(TargetPlatform platform) {
switch (platform) {
case TargetPlatform.iOS:
{
type = PlatformType.mobile;
name = PlatformName.iOS;
company = PlatformCompany.apple;
}
break;
case TargetPlatform.android:
{
type = PlatformType.mobile;
name = PlatformName.android;
company = PlatformCompany.google;
}
break;
case TargetPlatform.macOS:
{
type = PlatformType.desktop;
name = PlatformName.macOs;
company = PlatformCompany.apple;
}
break;
case TargetPlatform.windows:
{
type = PlatformType.desktop;
name = PlatformName.windows;
company = PlatformCompany.microsoft;
}
break;
default:
{
type = PlatformType.desktop;
name = PlatformName.linux;
company = PlatformCompany.linux;
}
}
}