本文属于记事
1、如果卡纸了,取出来后,需要重启
Submitted by gouki on 2022, July 19, 12:51 PM
本文属于记事
Submitted by gouki on 2022, June 29, 9:45 PM
在使用GetView的时候(其实StatelessWidget也一样)。只要使用了getX的Map<String,dynamic>,不管是get还是set,都会报setState的错误,(setState() or markNeedsBuild() called during build)。说白了和上次的问题一样:flutter中页面渲染完成的回调,但这次没有办法使用。上次是设置变量,这次是直接读变量。
当然,即使报错了,但页面还是可以正常渲染,上次是直接就红屏了。因为在项目中,没有细看原理,想了下还是应该没有设置初始值导致的。所以特别设置了一下初始值。问题解决。
做个笔记。
Submitted by gouki on 2022, June 28, 1:16 AM
这玩意就有点象vue中的mounted/或者其他的afterLoad等操作。怎么突然想要用到这个呢,是因为我用了getX,之前用riverpod,也没注意过这个问题。用了GetX之后,这个东西就被派上用场了。
原因是我有一个设置背景图的功能。本来想着一切换页面,背景图就加载出来,但事实上我把这个功能提前后,进入页面就直接报错,说是obx在页面没有渲染完成的时候不能调用。
This Obx widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
于是,使用:
WidgetsBinding.instance.addPostFrameCallback((time) {
final back = Get.find<BackgroundController>();
back.set(Assets.backgroundImage);
});
问题解决
Submitted by gouki on 2022, June 7, 10:25 PM
比如我们常用的alertDialog,只要显示一个message,不显示title的话,有点象toast。这时候如何自定义宽度 呢?
Submitted by gouki on 2022, June 5, 8:49 PM
正常情况下,我们都知道,flutter使用getx的时候,只要在Obx方法中都可以监听变量的变更,同时会局部刷新Obx包裹的Widget,但如果GetxController绑定的变量是list的时候,你会发现,无论你怎么 处理,Widget都不刷新。
有个最简单的办法:在设置变量的时候,同时让他refresh一下。比如:
count.value.add(1);
count.refresh();
这时候再看Widget就都更新了。
纯记录