嗨,我对测试加载状态很简单。
abstract class _AccountStore with Store {
@observable
bool loadingButtonStatus = false;
@observable
bool get loading => loadingButtonStatus;
@action
Future updateAccount(formData) async {
loadingButtonStatus = true;
Future.delayed(Duration(milliseconds: 2000)).then((future) {
loadingButtonStatus = false;
}).catchError((e) {
loadingButtonStatus = false;
print(e);
});
}
}
这是我的小部件
AccountStore store = AccountStore();
Observer(
name: 'loading_button',
builder: (_) => LoadingButton(
loading: store.loading,
text: Text('Save'),
onPressed: () {
store.updateAccount({});
},
))
但是每次我运行代码时,它总会返回我:There are no observables detected in the builder function
我尝试过更改用法store.loadingButtonStatus
仍然相同。
任何解决方案?
谢谢。
如果使用吸气剂,则必须使用@computed。
@observable
bool _loadingButtonStatus = false;
@computed
bool get loading => _loadingButtonStatus;