getDeviceInfo static method

Future<DeviceInfo> getDeviceInfo()

Asynchronously fetches the device information.

This method retrieves device information using the DeviceInfoPlugin and returns an instance of DeviceInfo with the appropriate details based on the platform (Android or iOS).

Returns:

Implementation

static Future<DeviceInfo> getDeviceInfo() async {
  final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();

  final BaseDeviceInfo deviceInfoPlatform = await deviceInfo.deviceInfo;

  if (deviceInfoPlatform is AndroidDeviceInfo) {
    // Android-specific info
    final androidInfo = await deviceInfo.androidInfo;
    return DeviceInfo(
      deviceName: androidInfo.brand,
      deviceModel: androidInfo.model,
      operatingSystem: "Android",
      systemVersion: androidInfo.version.release,
      deviceUuid: androidInfo.serialNumber,
    );
  } else if (deviceInfoPlatform is IosDeviceInfo) {
    // iOS-specific info
    final iosInfo = await deviceInfo.iosInfo;
    return DeviceInfo(
      deviceName: iosInfo.name,
      deviceModel: iosInfo.model,
      operatingSystem: "iOS",
      systemVersion: iosInfo.systemVersion,
      deviceUuid: iosInfo.identifierForVendor ?? iosInfo.utsname.machine,
    );
  } else {
    // Unknown platform
    return DeviceInfo(
      deviceName: "Unknown",
      deviceModel: "Unknown",
      operatingSystem: "Unknown",
      systemVersion: "Unknown",
      deviceUuid: "Unknown",
    );
  }
}