detectPlatformsInsideWeb method
detectPlatformsInsideWeb Method Documentation :
The detectPlatformsInsideWeb
function is a utility for detecting the current web platform and populating platform-related information.
Usage:
PlatformType type;
PlatformName name;
PlatformCompany company;
detectPlatformsInsideWeb();
// Now 'type', 'name', and 'company' hold information about the current web platform.
print('Platform Type: $type');
print('Platform Name: $name');
print('Platform Company: $company');
Overview:
- This utility function detects the current web platform and populates platform-related information based on the user agent.
Detection Process:
- It retrieves the user agent information using
window.navigator.userAgent
. - Based on the user agent, it sets the values for
type
,name
, andcompany
.
Supported Web Platforms:
- iOS: Detected when the user agent contains "iphone" or "ipad".
- Android: Detected when the user agent contains "android".
- macOS: Detected when the user agent contains "macintosh".
- Windows: Detected when the user agent contains "windows".
- Linux: Detected when the user agent contains "linux".
Platform Type Enumeration:
- PlatformType.web : Represents the web platform.
Platform Name Enumeration (for Web):
- PlatformName.iOS : iOS web platform.
- PlatformName.web_android : Android web platform.
- PlatformName.web_macOs : macOS web platform.
- PlatformName.web_windows : Windows web platform.
- PlatformName.web_linux : Linux web platform.
Platform Company Enumeration (for Web):
- PlatformCompany.apple : Apple Inc.
- PlatformCompany.google : Google LLC.
- PlatformCompany.microsoft : Microsoft Corporation.
- PlatformCompany.linux : Linux Community.
Implementation
detectPlatformsInsideWeb(String userAgent) {
if (userAgent.contains(PlatformUserAgents.iphone.name) ||
userAgent.contains(PlatformUserAgents.ipad.name)) {
type = PlatformType.web;
name = PlatformName.web_iOS;
company = PlatformCompany.apple;
}
if (userAgent.contains(PlatformUserAgents.android.name)) {
type = PlatformType.web;
name = PlatformName.web_android;
company = PlatformCompany.google;
}
if (userAgent.contains(PlatformUserAgents.macintosh.name)) {
type = PlatformType.web;
name = PlatformName.web_macOs;
company = PlatformCompany.apple;
}
if (userAgent.contains(PlatformUserAgents.windows.name)) {
type = PlatformType.web;
name = PlatformName.web_windows;
company = PlatformCompany.microsoft;
}
if (userAgent.contains(PlatformUserAgents.linux.name)) {
type = PlatformType.web;
name = PlatformName.web_linux;
company = PlatformCompany.linux;
}
}