device_identity/example/lib/main.dart
宏谋刘 161d9c18f3 1.0
2023-05-10 16:07:15 +08:00

86 lines
2.0 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:device_identity/device_identity.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> {
@override
void initState() {
super.initState();
register();
}
/// 同意协议时调用
Future<void> register() async {
await DeviceIdentity.register();
}
/// 获取AndroidId
Future<void> getAndroidId() async {
String androidId = await DeviceIdentity.androidId;
print("getAndroidId$androidId");
}
/// 获取imei
Future<void> getImei() async {
String imei = await DeviceIdentity.imei;
print("getImei$imei");
}
/// 获取oaid
Future<void> getOaid() async {
String oaid = await DeviceIdentity.oaid;
print("getOaid$oaid");
}
/// 获取ua
Future<void> getUa() async {
String ua = await DeviceIdentity.ua;
print("getUa$ua");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: SingleChildScrollView(
child: Column(
children: [
ElevatedButton(
onPressed: getAndroidId, child: const Text("获取AndroidId")),
const SizedBox(
height: 20,
),
ElevatedButton(onPressed: getImei, child: const Text("获取imei")),
const SizedBox(
height: 20,
),
ElevatedButton(onPressed: getOaid, child: const Text("获取oaid")),
const SizedBox(
height: 20,
),
ElevatedButton(onPressed: getUa, child: const Text("获取ua")),
],
),
),
),
),
);
}
}