How to check the device OS version from Flutter?

前端 未结 4 779
-上瘾入骨i
-上瘾入骨i 2020-12-15 05:30

Platform.operatingSystem will tell you whether you\'re running on Android or iOS.

How can I check which version of the device OS am I running on?

4条回答
  •  有刺的猬
    2020-12-15 06:17

    import 'dart:io' show Platform;
    
    void main() {
      // Get the operating system as a string.
      String os = Platform.operatingSystem;
      // Or, use a predicate getter.
      if (Platform.isMacOS) {
        print('is a Mac');
      } else {
        print('is not a Mac');
      }
    }
    

    Dart SDK > dart:io > Platform

    Here is the official article above, and if you want to check it is IOS or Andriod, you can use:

    if (Platform.isIOS) {
      print('is a IOS');
    } else if (Platform.isAndroid) {
      print('is a Andriod');
    } else {
    }
    

提交回复
热议问题