How to Identify Platform in Flutter

Flutter is available for various platforms. This includes Android, iOS, Mac, Windows, Linux etc. So, when you are developing apps for multiple platforms, for example, a hybrid mobile app for android and ios, then it’s necessary to know how to detect platform in flutter.

You can get the platform details using the Platform widget. With it, you can get operating system name as given below.

import 'dart:io';

String os = Platform.operatingSystem;

The Platform class helps to write platform specific code easily. For example, if you want to do something specifically with Android os then you can write code as given below.

if (Platform.isAndroid) {
  } else {

Like isAndroid, you can also use isIOS, isWindows, isMacOS, isLinux etc. This helps us to write platform specific code easily in flutter.

I hope you understand how to detect platform in flutter. Stay tuned for more tutorials.

Similar Posts

Leave a Reply