unique_identifier 0.3.0 unique_identifier: ^0.3.0 copied to clipboard
A new Flutter plugin for fetching the unique identifier from android and ios.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:unique_identifier/unique_identifier.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _identifier = 'Unknown';
@override
void initState() {
super.initState();
initUniqueIdentifierState();
}
Future<void> initUniqueIdentifierState() async {
String identifier;
try {
identifier = (await UniqueIdentifier.serial)!;
} on PlatformException {
identifier = 'Failed to get Unique Identifier';
}
if (!mounted) return;
setState(() {
_identifier = identifier;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: new Center(
child: new Text('Running on device with id: $_identifier\n'),
),
),
);
}
}