Skip to main content

stable_device_id 0.2.0 copy "stable_device_id: ^0.2.0" to clipboard
stable_device_id: ^0.2.0 copied to clipboard

A device identifier that survives app updates and reinstalls: ANDROID_ID or Widevine on Android and a Keychain-backed UUID on iOS.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:stable_device_id/stable_device_id.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _defaultId = 'Loading…';
  String _widevineId = 'Loading…';

  @override
  void initState() {
    super.initState();
    _loadIds();
  }

  Future<String> _read(AndroidIdSource source) async {
    try {
      return await StableDeviceId.getId(androidSource: source);
    } on PlatformException catch (e) {
      return 'Unavailable (${e.code})';
    }
  }

  Future<void> _loadIds() async {
    final defaultId = await _read(AndroidIdSource.androidId);
    final widevineId = await _read(AndroidIdSource.widevine);

    if (!mounted) return;

    setState(() {
      _defaultId = defaultId;
      _widevineId = widevineId;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('stable_device_id example')),
        body: Padding(
          padding: const EdgeInsets.all(24),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Text('Default (ANDROID_ID / Keychain)'),
              SelectableText('Device id: $_defaultId'),
              const SizedBox(height: 24),
              const Text('Android: Widevine'),
              SelectableText('Widevine id: $_widevineId'),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
160
points
17
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A device identifier that survives app updates and reinstalls: ANDROID_ID or Widevine on Android and a Keychain-backed UUID on iOS.

Repository (GitHub)
View/report issues

Topics

#device-id #device-identifier #keychain #android-id

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on stable_device_id

Packages that implement stable_device_id