Flutter中使用device_info获取设备信息
1. 安装插件
配置 device_info 插件。
dependencies:flutter:sdk: flutter# 设备信息device_info: ^2.0.2
在pubspec.yaml中配置保存后,在开发工具环境中会自动下载依赖包。
如果无法正常下载,执行 flutter pub get 。
2. 引入依赖
在需要用到的该插件的文件中引入插件包。
// 引入插件
import 'package:device_info/device_info.dart';
3. 使用插件
苹果设备:
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
print('设备唯一标识:${iosInfo.identifierForVendor}');
// 更多信息请查看 AndroidDeviceInfo 类中的定义
安卓设备:
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
print('设备唯一标识: ${androidInfo.androidId}');
// 更多信息请查看 IosDeviceInfo 类中的定义
4. 完整示例
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> {@overridevoid 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 类中的定义}@overrideWidget build(BuildContext context) {return Container(child: Scaffold(appBar: AppBar(title: Text("设备信息"),),));}
}
参考:https://pub.flutter-io.cn/packages/device_info
Flutter 获取设备信息
获取当前设备平台
获取屏幕宽高
获取状态栏高度
获取当前设备平台
第一种,直接通过Platform类来判断,不需要任何参数,很方便
Platform.isAndroid;
Platform.isFuchsia;
Platform.isIOS;
Platform.isLinux;
Platform.isMacOS;
第二种,通过ThemeData拿到TargetPlatform,然后在判断也可以
final ThemeData theme = Theme.of(context);
TargetPlatform targetPlatform = theme.platform;
switch(targetPlatform){
case TargetPlatform.android:
break;
case TargetPlatform.fuchsia:
// TODO: Handle this case.
break;
case TargetPlatform.iOS:
// TODO: Handle this case.
break;
}
获取屏幕宽高
///屏幕size
static Size screenSize(BuildContext context) {
return MediaQuery.of(context).size;
}
/// 屏幕宽度
static double screenWidth(BuildContext context) {
return MediaQuery.of(context).size.width;
}
/// 屏幕高度
static double screenHeight(BuildContext context) {
return MediaQuery.of(context).size.height;
}
获取状态栏高度
MediaQuery.of(context).padding.top
————————————————
版权声明:本文为CSDN博主「AnyEnter」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhuqian886/article/details/109111999
2、获取信息
android版本所有属性
/// Android operating system version values derived from `android.os.Build.VERSION`.final AndroidBuildVersion version;/// The name of the underlying board, like "goldfish".final String board;/// The system bootloader version number.final String bootloader;/// The consumer-visible brand with which the product/hardware will be associated, if any.final String brand;/// The name of the industrial design.final String device;/// A build ID string meant for displaying to the user.final String display;/// A string that uniquely identifies this build.final String fingerprint;/// The name of the hardware (from the kernel command line or /proc).final String hardware;/// Hostname.final String host;/// Either a changelist number, or a label like "M4-rc20".final String id;/// The manufacturer of the product/hardware.final String manufacturer;/// The end-user-visible name for the end product.final String model;/// The name of the overall product.final String product;/// An ordered list of 32 bit ABIs supported by this device.final List<String> supported32BitAbis;/// An ordered list of 64 bit ABIs supported by this device.final List<String> supported64BitAbis;/// An ordered list of ABIs supported by this device.final List<String> supportedAbis;/// Comma-separated tags describing the build, like "unsigned,debug".final String tags;/// The type of build, like "user" or "eng".final String type;/// `false` if the application is running in an emulator, `true` otherwise.final bool isPhysicalDevice;
ios版本所有属性:
/// Device name.final String name;/// The name of the current operating system.final String systemName;/// The current operating system version.final String systemVersion;/// Device model.final String model;/// Localized name of the device model.final String localizedModel;/// Unique UUID value identifying the current device.final String identifierForVendor;/// `false` if the application is running in a simulator, `true` otherwise.final bool isPhysicalDevice;/// Operating system information derived from `sys/utsname.h`.final IosUtsname utsname;
好吧,只要一行依赖就可以集成两个平台的项目代码,毫无繁琐配置,flutter真的简单。
Flutter中使用device_info获取设备信息相关推荐
- react获取设备高_React-Native 获取设备信息, Android获取IEMI码
简单介绍 关于引入上面的依赖, 链接中都有说明, 算了还是说一遍吧: **注意: ** 这里只说 Android 的配置步骤, IOS请去链接中查看 1: 获取设备信息 react-native-de ...
- HTML5+获取设备信息
阿里云低价服务器1折特惠,优惠爽翻天,点我立即低价购买 Device模块管理设备信息,用于获取手机设备的相关信息,如IMEI.IMSI.型号.厂商等.通过plus.device获取设备信息管理对象. ...
- 人脸识别/车牌识别视频智能分析系统EasyCVR通过接口GetApiV1Devices调用获取设备信息不成功原因分析
EasyCVR视频智能分析平台支持人脸识别和车牌识别,已经在很多项目中落地.同时,EasyCVR支持很多不同协议的设备接入,包括RTSP.GB28181.Ehome.海康SDK.大华SDK等协议. 用 ...
- uniGUI获取设备信息
有时候我们需要知道客户是使用什么设备登录的系统,在uniGUI中可以通过UniApplication.UniPlatform来获取. 简单记录一下,uniGUI的资料不太多,需要深入了解的,请多看DE ...
- java 自己实现 解析处理user-agent 获取设备信息 ip-ua转化归因
前景提要 最近在做app投放的转化归因,几个搜索平台并不一定能获取到muid,于是需要用到ip-ua归因模式 网上粗略搜了一下,发现许多文章ua处理用的uaparser又或者user-agent-ut ...
- iOS获取设备信息和获取当前屏幕状态
建议使用单利然后定义一个宏放到pch里, 这样比较方便下面是自己封装的一个类. (获取设备信息)上代码 /* CurrentDevice.h */ /* 提供两种单利创建方式 */ #import & ...
- Android 集成FCM(Google 推送)导致上架失败,提前获取设备信息ANDROID ID
又来记笔记 大佬们~~ 近期启用之前的项目上架,首先上架的是华为市场,发现一大堆问题,各种审核被拒,搞得问候了审核员的亲戚几次,一次给你来一两条,不会全部一次性给完.奈何别人的大公司.... 大致总结 ...
- 03 SkeyeVSS国标视频汇聚云服务使用Onvif协议进行摄像机设备接入以及获取设备信息
SkeyeVSS国标视频融合云平台基于端-边-云一体化架构,部署轻量简单.功能灵活多样,平台可支持多协议(GB28181/RTSP/Onvif/海康SDK/Ehome/大华SDK/RTMP推流等).多 ...
- html5获取设备信息 视频,设备信息的管理(Device) ---- HTML5+
Device模块管理设备信息,用于获取手机设备的相关信息,如IMEI.IMSI.型号.厂商等.通过plus.device获取设备信息管理对象. 应用场景:打电话,铃声提醒,震动提醒,音量设置,查看设备 ...
最新文章
- 函数项目一个超感人的故事:关于swfupload在某些环境下面session丢失的完美解决方案(看完我哭了)...
- c语言从键盘输入千米数,第二章 C语言编程基础.ppt
- Hadoop源码导入Eclipse
- 【Android 逆向】Android 进程注入工具开发 ( SO 进程注入环境及 root 权限获取 | 进程注入时序分析 )
- Hadoop1.2.1伪分布模式安装指南
- PM2中无法开启ES6的解决方案
- 高并发02_同步锁的一些题目
- C语言内存管理之结构体
- 从0到1写RT-Thread内核——支持多优先级
- 北京供销大数据集团BGP网络商用 经实测网络质量优异
- 通力法评 | 《证券基金经营机构信息技术管理办法》解读
- 安装matlab7.0步骤,Matlab 7.0 安装指导
- 好看的思维导图案例,你想做出来吗
- Python 写一个简单的FTPv2
- 计算机英语领域有哪些构词法,计算机专业英语的构词方法(共2969字).doc
- htts 及 tomcat ssl配置
- 【饿了么】—— Vue2.0高仿饿了么核心模块移动端Web App项目爬坑(一)
- STM32+华为云IOT制作酒驾监控系统:上车就监控
- 【代码】C++实现二叉树基本操作及测试用例
- 关于CSAPP的学习:如何与如同机翻的文字搏斗及如何快速理解冗长的说明
热门文章
- 微积分基本定理:微分符号与积分符号是逆运算
- 阿童木录机固态硬盘MOV视频损坏修复
- Html5 Egret游戏开发 成语大挑战(一)开篇
- Centos7(VPS)更改为中国时区并定期同步
- css3制作吃豆豆动画
- Java使用@Value获取不到值
- 12岁的微博回港上市,还有新故事吗?
- 在eclips中配置maven
- cas112592-50-4/四溴苯基卟啉镍/nickel(II) tetra(p-Br-phenyl)porphyrin/分子式:C44H24Br4N4Ni++/分子量:986.99800
- 用计算机管理从新分区,电脑如何分区硬盘分区_电脑怎么重新分区教程-win7之家...