How do you detect the host platform from Dart code? How do you detect the host platform from Dart code? dart dart

How do you detect the host platform from Dart code?


import 'dart:io' show Platform;if (Platform.isAndroid) {  // Android-specific code} else if (Platform.isIOS) {  // iOS-specific code}

All options include:

Platform.isAndroidPlatform.isFuchsiaPlatform.isIOSPlatform.isLinuxPlatform.isMacOSPlatform.isWindows

You can also detect if you are running on the web using kIsWeb, a global constant indicating if the application was compiled to run on the web:

import 'package:flutter/foundation.dart' show kIsWeb;if (kIsWeb) {  // running on the web!} else {  // NOT running on the web! You can check for additional platforms here.}


Thanks to Collin, the final answer is:

bool isIOS = Theme.of(context).platform == TargetPlatform.iOS;


import 'dart:io' show Platform;  //at the topString os = Platform.operatingSystem; //in your codeprint(os);