摘要:在生产环境的开发过程中,获取设备信息是必不可少的一步,本文详细介绍在中如何判断平台是还是,并使用开源库获取和的设备信息。
在生产环境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.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn2、获取信息 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 Listios版本所有属性:supported32BitAbis; /// An ordered list of 64 bit ABIs supported by this device. final List supported64BitAbis; /// An ordered list of ABIs supported by this device. final List 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;
/// 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讨论
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/17053.html
摘要:在本文中,我们将带大家进一步了解的搭建与运行。操作系统或更高版本磁盘空间工具依赖或更新的版本和命令行工具这些命令行工具。运行应用程序定位到工具栏在中选择一个运行该应用的设备。 作者:个推iOS开发工程师 伊泽瑞尔 Flutter是Google推出的跨平台的解决方案,用以帮助开发者在 Android 和 iOS 两个平台开发高质量原生应用的全新移动 UI 框架。 之前我们为大家介绍了《跨...
摘要:在本文中,我们将带大家进一步了解的搭建与运行。操作系统或更高版本磁盘空间工具依赖或更新的版本和命令行工具这些命令行工具。运行应用程序定位到工具栏在中选择一个运行该应用的设备。作者:个推iOS开发工程师 伊泽瑞尔Flutter是Google推出的跨平台的解决方案,用以帮助开发者在 Android 和 iOS 两个平台开发高质量原生应用的全新移动 UI 框架。 之前我们为大家介绍了《跨平台框架F...
摘要:在函数内部,会调用函数,函数内部会扫描修改的文件,并将文件修改前后进行对比,随后会将被改动的代码生成一个文件。随后会通过将生成的文件发送给虚拟机,虚拟机拿到文件后会调用函数进行资源重载,将文件注入正在运行的中。 该文章属于原创,转载请注明: https://www.jianshu.com/p/1a90adc09e99 showImg(https://segmentfault.com...
摘要:注释处的方法是程序的入口,使用了符号,这是中单行函数或方法的简写,等价于如下代码方法是框架的入口,如果不返回方法,那么执行的是一个控制台应用。 本文首发于微信公众号「刘望舒」 前言 最近的Google I/O大会上,Flutter1.5 开始支持移动、Web、桌面和嵌入式设备,从不温不火的sky一直进化到如今热门的Flutter,Flutter的发展已经超出很多人的想象。我对跨平台技术一...
摘要:在本文中,我们将带大家进一步了解的搭建与运行。操作系统或更高版本磁盘空间工具依赖或更新的版本和命令行工具这些命令行工具。运行应用程序定位到工具栏在中选择一个运行该应用的设备。 作者:个推iOS开发工程师 伊泽瑞尔 Flutter是Google推出的跨平台的解决方案,用以帮助开发者在 Android 和 iOS 两个平台开发高质量原生应用的全新移动 UI 框架。 之前我们为大家介绍了《跨...
阅读 2320·2021-11-18 10:02
阅读 915·2021-11-15 18:00
阅读 3126·2021-09-30 09:46
阅读 2206·2021-09-27 13:35
阅读 2513·2021-09-22 15:18
阅读 1361·2021-09-06 15:00
阅读 1820·2021-09-04 16:45
阅读 554·2019-08-30 15:55