android_id 0.3.6 copy "android_id: ^0.3.6" to clipboard
android_id: ^0.3.6 copied to clipboard

PlatformAndroid

A Flutter plugin for getting the Android ID. Only for Android.

example/lib/main.dart

import 'dart:async';

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

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  static const _androidIdPlugin = AndroidId();

  var _androidId = 'Unknown';

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

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

    // 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(() => _androidId = androidId);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Android ID: $_androidId'),
        ),
      ),
    );
  }
}
104
likes
140
pub points
99%
popularity

Publisher

verified publisherachim.io

A Flutter plugin for getting the Android ID. Only for Android.

Repository (GitHub)
View/report issues

Topics

#androidid #device #identifier #android #native

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on android_id