判断操作系统

判断操作系统

Use Platform.operatingSystem to get the operating system as a String. Or, use the isMacOS, isAndroid, isLinux, and isWindows static getters defined in Platform.

import 'dart:io' show Platform, stdout;

main() {
  // Get the operating system as a string.
  String os = Platform.operatingSystem;

  // Or, use predicate getters for checking the operating system.
  stdout.write("You are using ");
  if (Platform.isMacOS) {
    stdout.writeln('a Mac');
  } else if (Platform.isAndroid) {
    stdout.writeln('an Android device');
  } else if (Platform.isIOS) {
    stdout.writeln('an iOS device');
  } else if (Platform.isLinux) {
    stdout.writeln('Linux');
  } else if (Platform.isWindows) {
    stdout.writeln('Windows');
  } else {
    stdout.writeln('something other than MacOS, Android, Linux, or Windows');
  }
}

手机扫码阅读