mobile_device_identifier 0.0.2 copy "mobile_device_identifier: ^0.0.2" to clipboard
mobile_device_identifier: ^0.0.2 copied to clipboard

Flutter package to obtain unique ID from mobile device (android / ios)

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:mobile_device_identifier/mobile_device_identifier.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 _deviceId = 'Unknown';
  final _mobileDeviceIdentifierPlugin = MobileDeviceIdentifier();

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

  Future<void> initDeviceId() async {
    String deviceId;
    try {
      deviceId = await _mobileDeviceIdentifierPlugin.getDeviceId() ??
          'Unknown platform version';
    } on PlatformException {
      deviceId = 'Failed to get platform version.';
    }

    if (!mounted) return;
    setState(() {
      _deviceId = deviceId;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Mobile device identifier'),
        ),
        body: Center(
          child: Padding(
              padding: const EdgeInsets.all(10),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('Device ID : \n$_deviceId'),
                  const Divider(height: 30, color: Colors.transparent),
                  Builder(builder: (context) {
                    String encoded = base64.encode(utf8.encode(_deviceId));
                    return Text("Device ID Encoded : \n$encoded");
                  })
                ],
              )),
        ),
      ),
    );
  }
}
54
likes
150
pub points
95%
popularity

Publisher

unverified uploader

Flutter package to obtain unique ID from mobile device (android / ios)

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mobile_device_identifier