I want to check in Web if I'm running in Android, iOS, or other (desktop).
"Platform.isAndroid" or any other call that uses Platform works only for mobile and desktop apps.
Thanks.
You can check the platform in a web environment using JavaScript within Dart (Flutter Web) like this:
import 'dart:html' as html;
String getPlatform() {
final userAgent = html.window.navigator.userAgent.toLowerCase();
if (userAgent.contains('android')) {
return 'Android';
} else if (userAgent.contains('iphone') || userAgent.contains('ipad') || userAgent.contains('ipod')) {
return 'iOS';
} else {
return 'Other (Desktop)';
}
}
void main() {
print(getPlatform()); // Example usage
}
This checks the userAgent string from the browser and determines whether the user is on Android, iOS, or another platform (desktop).