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

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close