在flutter中判断平台,获取设备信息

在flutter中判断平台,获取设备信息,第1张

概述在生产环境app的开发过程中,获取设备信息是必不可少的一步,本文详细介绍在flutter中如何判断平台是android还是ios,并使用开源库device_info获取android和ios的设备信息。 判断平台 这步很简单,导入平台Platform库就行,位置在dart:io import 'dart:io'; 然后在android studio中编辑的时候就有快捷菜单了: 判断平台只要使用如下

在生产环境app的开发过程中,获取设备信息是必不可少的一步,本文详细介绍在Flutter中如何判断平台是androID还是ios,并使用开源库device_info获取androID和ios的设备信息。

判断平台

这步很简单,导入平台Platform库就行,位置在dart:io

import 'dart:io';

然后在androID studio中编辑的时候就有快捷菜单了:

判断平台只要使用如下代码:

if(Platform.isIOS){      //ios相关代码    }else if(Platform.isAndroID){      //androID相关代码    }
device_info库的使用

先上图

1、添加依赖

在pubspec.yml中的dependencIEs下面新增节点

device_info : ^0.2.0

上图比较快:

然后点下编辑器的"Packages get"或者运行命令行:

Flutter packages get

注意这里可能需要配置环境变量:

export PUB_HOSTED_URL=https://pub.Flutter-io.cnexport FlutteR_STORAGE_BASE_URL=https://storage.Flutter-io.cn
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真的简单。

如有疑问,请加qq群854192563讨论

总结

以上是内存溢出为你收集整理的在flutter中判断平台,获取设备信息全部内容,希望文章能够帮你解决在flutter中判断平台,获取设备信息所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004058.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存