Skip to content
The Chat Archive
claude-2.1· Anthropic Arena Human Preference 55K

I have a provider in Flutter, i need to obtain an unique device id for the mobile device…

  1. User

    I have a provider in Flutter, i need to obtain an unique device id for the mobile device that doesn't change overtime

  2. Assistant

    Here are a few ways to get a unique device identifier in Flutter that persists across app installs:

    1. Use the device_info plugin to get the device UUID:
    import 'package:device_info/device_info.dart';
    
    String uuid = await DeviceInfoPlugin().getDeviceId();
    
    1. Use the uuid package to generate a random UUID that will persist on the device:
    import 'package:uuid/uuid.dart';
    
    String uuid = Uuid().v1(); // Create random UUID
    
    1. For Android devices, you can get the Android ID which is unique for each device:
    import 'package:device_info/device_info.dart';
    
    String androidId = await DeviceInfoPlugin().androidInfo.then((info) {
      return info.androidId; 
    });
    
    1. For iOS devices, you can get the identifierForVendor which persists across app installs:
    import 'package:device_info/device_info.dart';  
    
    String iosId = await DeviceInfoPlugin().iosInfo.then((info) {
      return info.identifierForVendor;
    });
    

    The device_info plugin works across iOS and Android and is likely the easiest way to get a persistent unique ID. The UUID package also works well if you just need a random ID.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.