device_info – Detect platform and OS version in Flutter

device_info is a package that allows developers to get Android and iOS system information.

Install the package:

device_info: ^1.0.0

Then its classes can be imported with package:device_info/device_info.dart in a Dart file.

DeviceInfoPlugin class in this package can provide device and operating system information. Each OS, Android, and iOS, have its own getters to get platform-specific device information.

if (Platform.isAndroid) {
  var androidInfo = await DeviceInfoPlugin().androidInfo;    
  print("Android ${androidInfo.version.release} on ${androidInfo.model}")
} else if (Platform.isIOS) {
  var iosInfo = await DeviceInfoPlugin().iosInfo;
  print("iOS ${iosInfo.systemVersion} on ${iosInfo.name}")
}

The code first checks whether the current platform is Android or iOS using the static properties isAndroid and isIOS of the Platform class provided by the Flutter framework.

If the current platform is Android, the code creates an instance of DeviceInfoPlugin class, which is a Flutter plugin used to retrieve device information. The androidInfo property is then used to get the Android version and model of the device, which are printed out using the print() method.

If the current platform is iOS, the code creates an instance of DeviceInfoPlugin class and retrieves information about the iOS device using the iosInfo property. The system version and device name are then printed out using the print() method.

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top