getDeviceId static method

Future<String?> getDeviceId()

Returns the device's unique identifier (ID) based on platform.

  • Returns the iOS vendor identifier for iOS devices.
  • Returns the Android device ID for Android devices.
  • Returns the web browser name for web.

Implementation

static Future<String?> getDeviceId() async {
  var deviceInfo = DeviceInfoPlugin();
  if (Platform.isIOS) {
    var iosDeviceInfo = await deviceInfo.iosInfo;
    return iosDeviceInfo.identifierForVendor;
  } else if (Platform.isAndroid) {
    var androidDeviceInfo = await deviceInfo.androidInfo;
    return androidDeviceInfo.id;
  } else if (kIsWeb) {
    var webDeviceInfo = await deviceInfo.webBrowserInfo;
    return webDeviceInfo.browserName.toString();
  }
  return null;
}