flutter 获取设备信息

发布时间:2022-01-27 22:43:35

在不使用登录的情况下 就需要获取设备标识来作为用户的唯一标识

1.在pubspec.yaml中的dependencies加入设备插件的依赖

device_info : ^0.4.0+1

2.在dart引入包

import 'package:device_info/device_info.dart';
import 'dart:io';

3.获取设备信息的代码

DeviceInfoPlugin deviceInfo = new DeviceInfoPlugin();
    if(Platform.isIOS){
      print('IOS设备:');
      IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
    }else if(Platform.isAndroid){
      print('Android设备');
      AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
    }

4.我使用的工具是androidstudio 运行控制台出现如下错误

Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:device_info
 - package:device_info_platform_interface
 - package:plugin_platform_interface

5.这个错误需要在android studio 运行的地方找到edit configurations打开界面 在Additional run args 输入框中添加如下代码

--no-sound-null-safety

Card image cap
APP STORE
Card image cap
应用宝
Card image cap
小米
Card image cap
华为