配置 device_info 插件。
dependencies:
flutter:
sdk: flutter
# 设备信息
device_info: ^1.0.0
在pubspec.yaml中配置保存后,在VS Code环境中会自动下载依赖包。
如果无法正常下载,执行 flutter pub get 。
在需要用到的该插件的文件中引入插件包。
// 引入插件
import 'package:device_info/device_info.dart';
苹果设备:
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
print('设备唯一标识:${iosInfo.identifierForVendor}');
// 更多信息请查看 AndroidDeviceInfo 类中的定义
安卓设备:
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
print('设备唯一标识: ${androidInfo.androidId}');
// 更多信息请查看 IosDeviceInfo 类中的定义
import 'package:flutter/material.dart';
// 引入插件
import 'package:device_info/device_info.dart';
class DevicePage extends StatefulWidget {
DevicePage({Key key}) : super(key: key);
@override
_DevicePageState createState() => _DevicePageState();
}
class _DevicePageState extends State<DevicePage> {
@override
void initState() {
super.initState();
// 获取设备信息
this._getDeviceInfo();
}
void _getDeviceInfo() async{
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
// 安卓系统
// AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
// print('设备唯一标识: ${androidInfo.androidId}');
// 更多信息请查看 AndroidDeviceInfo 类中的定义
// 苹果系统
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
print('设备唯一标识:${iosInfo.identifierForVendor}');
// 更多信息请查看 IosDeviceInfo 类中的定义
}
@override
Widget build(BuildContext context) {
return Container(
child: Scaffold(
appBar: AppBar(
title: Text("设备信息"),
),
)
);
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有