Flutter Differentiate between devices via unique ID / IMEI / Serialnumber?

1.1k views Asked by At

I wanted to know if there is a prefered way to fetch a unique "ID" from the user of the app. The thing is that I need to differentiate between phones under one "Company Account".

As it seems, android and apple made it hard for us to get the needed information.

The best shot seems to be: https://pub.dev/packages/flutter_udid

But I just want to know if there is a better solution?

flutter_udid looks good, but I am a bit surprised that Android/Apple are giving us a hard time fetching a unique device UID

2

There are 2 answers

0
Furkan Olkay On

I understand you want to get device id. This id is unique and does not change until the device is reset. You can use it for identification.

platform_device_id: ^1.0.1

Add platform_device_id to your pubspec.yaml.

Here's code to get device Id using platform_device_id package.

import 'package:platform_device_id/platform_device_id.dart';

String? deviceId = await PlatformDeviceId.getDeviceId;
0
Kasun Hasanga On

Use device_info_plus plugin developed by Flutter community. This is how you can get IDs on both platform.

In your pubspec.yaml file add this:

dependencies:
  device_info_plus: ^3.2.3

Create a method:

Future<String?> _getId() async {
  var deviceInfo = DeviceInfoPlugin();
  if (Platform.isIOS) { // import 'dart:io'
    var iosDeviceInfo = await deviceInfo.iosInfo;
    return iosDeviceInfo.identifierForVendor; // unique ID on iOS
  } else if(Platform.isAndroid) {
    var androidDeviceInfo = await deviceInfo.androidInfo;
    return androidDeviceInfo.androidId; // unique ID on Android
  }
}

Usage:

String? deviceId = await _getId();