一. 前言
Flutter实战—获取设备信息。
二. 配置
1.添加依赖
device_info:Get current device information from within the Flutter application.
版本查询 : https://pub.dev/packages/device_info
1.1 在项目的pubspec.yaml
文件中添加依赖:device_info
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
//添加依赖
device_info: 0.4.0+2
1.2 安装下载依赖包
flutter packages get
2.配置IOS
如果需要在IOS运行,需要安装cocoapods和brew:
brew install cocoapods
pod setup
三. 代码步骤
1.获取平台信息
Flutter是全平台框架,可以在多种平台上运行,获取设备信息之前要先判断程序运行在哪种平台。
判断平台:通过dart.io
包下的PlatformPlatform
类来获取。
1.1 Platform类
class Platform {
...
static final bool isLinux = (_operatingSystem == "linux");
static final bool isMacOS = (_operatingSystem == "macos");
static final bool isWindows =