Flutter: How to get device details like UUID, deviceName?

We will use device_info package for finding these details. Use this link to check latest version of the package. 

Add package_info: ^0.4.0+3 in pubspec.yaml file of your project.
below 
dependencies:
  flutter:
    sdk: flutter
    package_info: ^0.4.0+3


Using next code sample you can retrieve the details.

Future<List<String>> getDeviceDetails() async {
    String deviceName;
    String deviceVersion;
    String identifier;
    final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
    try {
      if (Platform.isAndroid) {
        
        var build = await deviceInfoPlugin.androidInfo;
        deviceName = build.model;
        deviceVersion = build.version.toString();
        identifier = build.androidId; //UUID for Android
      } else if (Platform.isIOS) {
        var data = await deviceInfoPlugin.iosInfo;
        deviceName = data.name;
        deviceVersion = data.systemVersion;
        identifier = data.identifierForVendor; //UUID for iOS
      }
    } on Exception catch (e) {
      print('Failed to get platform version ${e.toString()}');
    }
    return [deviceName, deviceVersion, identifier];
  }
For Iphone it returns
[iPhone Xʀ, 12.2, 0EE6BD4D-FB32-4283-B9C2-BD235DD421CF]

Comments

Popular posts from this blog

Enhancing LLM Responses with Prompt Stuffing in Spring Boot AI

Automate Library Integration with Cursor's Agent Mode

Upload an image from Android to Google's app engine server