AVAILABLE: 5
The UI that should be slightly different on iOS and Android, so there needs to be a way to detect which application is running, but I couldn’t find it in the Flutter documentation. This includes when I want to perform error handling between iOS and Android, and thus I need a mechanism to check both platforms for my Flutter code.
import 'dart:io' show Platform;
if (Platform.isAndroid) {
// Android-specific code
} else if (Platform.isIOS) {
// iOS-specific code
}
If you are building a Flutter application for multiple platforms, not just Android and iOS, you can continue the checks as follows:
- Platform.isAndroid
- Platform.isFuchsia
- Platform.isIOS
- Platform.isLinux
- Platform.isMacOS
- Platform.isWindows
You can also detect whether you are running on the web using kIsWeb
, a global constant that indicates whether the app is 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.
}
References
- Platform documentation: https://api.flutter.dev/flutter/dart-io/Platform-class.html
- kIsWeb documentation: https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html