【发布时间】:2021-09-19 08:43:42
【问题描述】:
当用户移动容器和用户停止触摸容器时,我有一个改变颜色的小条。我正在使用侦听器小部件和 onPointerMove 函数,它调用值为 true 的 GetxController 和值为 false 的 onPointerUp,因此容器的颜色根据控制器中的 RxBool 变化。
我的问题是:在调用 onPointerMove 时,RxBool 更改为真实值,但我不知道该值是否总是发出,即使它相同,因为这样我的小部件每次都会重绘;或者如果该值没有发出任何内容,因为它是相同的。
这里是控制器
RxBool isPressing = false.obs;
void changeColor(bool i) => i ? isPressing.value = true : isPressing.value = false;
这是监听器小部件
Listener(
onPointerMove: (PointerEvent e) => _touchController.changeColor(true),
onPointerUp: (PointerUpEvent e) => _touchController.changeColor(false),
.
.
.
children: [
Obx(() => Container(
height: 100,
width: 4,
decoration: BoxDecoration(
color: _touchController.isPressing.value ? primaryColor : Colors.white,
borderRadius: BorderRadius.circular(10),
),
)),
【问题讨论】:
标签: flutter dart rxdart flutter-getx