当前位置:网站首页>Flutter中的GetX状态管理用起来真的那么香吗?
Flutter中的GetX状态管理用起来真的那么香吗?
2022-06-23 21:59:00 【InfoQ】
前言
- 主题切换:比如深色模式切换;
- 多语言:可以通过配置
Map搞定多语言;
- 弹窗提醒:包括了
SnackBar和对话框;
- 路由:无需
Context的路由跳转;
- 离线存储:不依赖原生的key-value 存储组件的离线存储
GetStorage;
- 状态管理:快速接入的响应式状态管理;
- 工具类:例如表单验证工具,获取系统参数(平台类型,屏幕尺寸等);
- 依赖注入容器:使用简单的
put和find方法完成容器对象的注册和获取;
- 网络请求:可以使用
GetConnect完成网络请求。

GetX 作者背景


GetX的客观评价
- 使用 GetX 的导航需要使用自定义的
MaterialApp或CupertinoApp,也就是我们需要使用GetMeterialApp或GetCupertinoApp包裹应用才能够在页面跳转时无需使用BuildContext。对应用的侵入性比较强。
- SnackBar、对话框和导航的使用上不太合理。在这些实现的内部使用了静态的
context,这使得单元测试没法直接晚餐,而需要使用 widget testing配合完成。
get_connect插件集成了 REST API 请求和 GraphQL 客户端。这有点多余,一般的应用不会二者都用,这会导致插件部分功能多余(推荐网络请求还是用 Dio)。
- 依赖注入和热重载问题(这点本人也发现了):GetX 的依赖注入还不太成熟,如果依赖对象改变后(比如修改了依赖对象类型,增加了依赖对象),直接热重载会报错,这个时候往往需要 reload 才行。
- 注释和文档比较糟糕(这点有同感): 源码很多地方缺少注释,导致未来的维护可能会比较麻烦。而官方文档相对也不是很完善,导致使用者需要自己摸索(确实,写这个系列的时候好多地方都是自己摸索出来的)。
- 代码组织性比较差:如果去阅读源码,会发现一个文件会有数百行,多个类、函数、变量都混在一个文件中。同时部分方法的命名也需要改进,比如路由的
Get.to,Get.toNamed,Get.offNamed,依赖注入的Get.put,Get.lazyPut等,这些方法名称如果不阅读文档很难推断出具体的功能。如果在方法和 Get 之间加一个模块名称会更好理解,比如Get.router.to,Get.dependencies.put。
- 很多代码没有经过测试:由于 GetX 覆盖的功能实在太多,很难做到每个功能特性都做完善的测试,这会使得其中可能存在隐藏的 Bug。
- 使用 GetX 的建议:建议只使用必要的模块,比如 GetX 的状态管理、响应式编程和依赖注入,而像导航和绑定这类的功能要慎用。
总结

边栏推荐
- Tencent lightweight + pagoda building document online preview project kkfileview
- C# Winform 自定义进度条ProgressBar
- TDD开发模式流程推荐
- The fortress machine installs pytorch, mmcv, and mmclassification, and trains its own data sets
- PHP的curl功能扩展基本用法
- SQL语句中EXISTS的详细用法大全
- CS1.6 service startup tutorial
- Go language core 36 lectures (go language practice and application 25) -- learning notes
- AIX系统月维护查什么(一)
- C# 读取内存条占用大小,硬盘占用大小
猜你喜欢
![[technical dry goods] the technical construction route and characteristics of zero trust in ant Office](/img/d1/ce999b9f72bbb8f692c4298b4042aa.png)
[technical dry goods] the technical construction route and characteristics of zero trust in ant Office

【设计】1359- Umi3 如何实现插件化架构

The sandbox week is coming!

Summary of some indicators for evaluating and selecting the best learning model

What is an immunohistochemical experiment? Immunohistochemical experiment

解密抖音春节红包背后的技术设计与实践
PostgreSQL怎么创建分区表详解

C#/VB. Net word to text

The national post office and other three departments: strengthen the security management of personal information related to postal express delivery, and promote the de identification technology of per

Million message IM system technical points sharing
随机推荐
How to use data warehouse to create time series
Understand the data consistency between MySQL and redis
2022 cloud consulting technology series storage & CDN special sharing meeting
Bilibili×蓝桥云课|线上编程实战赛全新上新!
Deserialization - PHP deserialization
Notes to nodejs (II)
ASM文件系统 数据如何写和读数据
【技术干货】蚂蚁办公零信任的技术建设路线与特点
The sandbox week is coming!
Four traversals of map sets
Apache log4j 2 reported high-risk vulnerability, coding teamed up with Tencent to protect software security
MySQL事务隔离
Website construction column setting form which website construction company is better
Application of clock synchronization system in banking system
How to choose the server for website construction, including which servers and how much to rent
Zynq Ultrascale+ RF Data Coverter IP配置 - ADC
2022云顾问技术系列之存储&CDN专场分享会
C language picture transcoding for performance testing
The principle of async and await
Unknown character set index for field ‘255‘ received from server.