如何知道手机操作系统是IOS还是android flutter

mar*_*wan 2 flutter

我尝试通过以下方式了解手机操作系统:flutter 应用程序中的 IOS 或 Android 是否正在其上运行:

  @override
  void initState() {
    super.initState();
    }
Run Code Online (Sandbox Code Playgroud)

以便在检测到操作系统后设置if条件。我怎样才能控制这个?有谁知道这个问题的解决方案?

Ayu*_*ana 5

import 'dart:io' show Platform;

if (Platform.isAndroid) {
  // Android-specific code
} else if (Platform.isIOS) {
  // iOS-specific code
}
Run Code Online (Sandbox Code Playgroud)

检查文档:

https://api.flutter.dev/flutter/dart-io/Platform-class.html