gskinnerTeam / flutter-universal-platform

A web-safe implementation of dart.io.Platforms. Helps avoid the "Unsupported operation: Platform._operatingSystem" runtime error.
MIT License
105 stars 27 forks source link

Add UniversalPlatform.value getter #7

Closed emme1444 closed 3 years ago

emme1444 commented 3 years ago

This exposes the current enum value.

This is useful in order to, for example, switch upon the current platform:

import 'package:universal_platform/universal_platform.dart';

void main() {
  String platformType;
  switch (UniversalPlatform.value) {
    case UniversalPlatformType.Web:
      platformType = "Web";
      break;
    case UniversalPlatformType.Android:
    case UniversalPlatformType.Fuchsia:
    case UniversalPlatformType.IOS:
      platformType = "Mobile";
      break;
    case UniversalPlatformType.Linux:
    case UniversalPlatformType.MacOS:
    case UniversalPlatformType.Windows:
      platformType = "Desktop";
      break;
  }

  print(platformType);
}

If you want me to add the example somehow, please let me know.

Thanks!