How to Get Device Info in Flutter

Flutter is a great platform for developing mobile apps, but one of the challenges can be getting detailed information about the devices your app is running on.

For example, you may want to show different UI elements on iOS and Android, or you may need to access specific features that are only available on certain OS versions. Thankfully, device_info_plus package makes it easy to check the platform and OS version with a few simple lines of code. 

This Flutter plugin provides detailed information about the device (make, model, etc.), and the Android or iOS version the app is running on. This can be really useful when you’re trying to diagnose issues or optimize your app for specific devices.

Install the package:

//you should check the package on pub.dev for latest version
device_info_plus: ^3.2.3

Detect platform

var deviceData = <String, dynamic>{};

    try {
      if (kIsWeb) {
        deviceData = _readWebBrowserInfo(await deviceInfoPlugin.webBrowserInfo);
      } else {
        if (Platform.isAndroid) {
          deviceData =
              _readAndroidBuildData(await deviceInfoPlugin.androidInfo);
        } else if (Platform.isIOS) {
          deviceData = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo);
        } else if (Platform.isLinux) {
          deviceData = _readLinuxDeviceInfo(await deviceInfoPlugin.linuxInfo);
        } else if (Platform.isMacOS) {
          deviceData = _readMacOsDeviceInfo(await deviceInfoPlugin.macOsInfo);
        } else if (Platform.isWindows) {
          deviceData =
              _readWindowsDeviceInfo(await deviceInfoPlugin.windowsInfo);
        }
      }
    } on PlatformException {
      deviceData = <String, dynamic>{
        'Error:': 'Failed to get platform version.'
      };
    }

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