detectPlatformsInsideWeb method

dynamic detectPlatformsInsideWeb(
  1. String userAgent
)

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, and company.

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:

Platform Name Enumeration (for Web):

Platform Company Enumeration (for Web):

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;
  }
}