原文传送门
一、属性监听刷新
1、声明属性
RxInt count = 0.obs;
RxString search = ''.obs;
2、属性事件监听
ever(count, (callback) {
print("用来监听数字的变化,--$count");
});
once(count, (callback) {
print("只会监听第一次数字的变化,--$count");
});
debounce(count, (callback) {
print("每次用户停止输入1秒时间调用,--$count");
},time: Duration(microseconds: 1000));
interval(count, (callback) {
print(" //每隔1秒输出一次 .,--$count");
},time: Duration(microseconds: 1000));
3、属性Widget监听
Obx(() {
int page = count.value; //获取监听值
return Text('$page');
})
二、直接刷新UI
1、包裹要刷新的组件
GetBuilder<CounterEasyLogic>(
builder: (logicGet) => Text(
'点击了 ${logicGet.count} 次',
style: TextStyle(fontSize: 30.0),
),
)
2、执行update方法可触发刷新
class CounterEasyLogic extends GetxController {
var count = 0;
void increase() {
++count;
update();
}
}