detectPlatforms method

dynamic detectPlatforms(
  1. TargetPlatform platform
)

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

Supported Platforms:

  • Mobile Platforms: iOS, Android
  • Desktop Platforms: macOS, Windows, Linux

Platform Type Enumeration:

Platform Name Enumeration:

Platform Company Enumeration:

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