native_id 0.0.5 copy "native_id: ^0.0.5" to clipboard
native_id: ^0.0.5 copied to clipboard

Get unique identifier for android and iOS

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:native_id/native_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 _nativeId = 'Unknown';
  String _uuid = 'Unknown';
  final _nativeIdPlugin = NativeId();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String nativeId;
    String uuid;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      nativeId = await _nativeIdPlugin.getId() ?? 'Unknown NATIVE_ID';
    } on PlatformException {
      nativeId = 'Failed to get native id.';
    }

    try {
      uuid = await _nativeIdPlugin.getUUID() ?? 'Unknown UUID';
    } on PlatformException {
      uuid = 'Failed to get uuid.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _nativeId = nativeId;
      _uuid = uuid;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SizedBox(
          width: double.infinity,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('NATIVE_ID: $_nativeId'),
              const SizedBox(height: 20),
              Text('UUID: $_uuid'),
            ],
          ),
        ),
      ),
    );
  }
}
4
likes
150
points
514
downloads
screenshot

Publisher

verified publisherkyawzayartun.com

Weekly Downloads

Get unique identifier for android and iOS

Repository (GitHub)
View/report issues

Topics

#imei #unique-identifier #utility

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on native_id