我的意思是检查刷新指示器是否正在刷新。根据该值采取行动以在该值为真时停止 Spinner 旋转。
Widget _productLogic(MainModel model) {
Widget content = Center(
child: Text("No products available."),
);
if (model.allProduct.length > 0 && !model.isLoading) {
content = _buildProductList(model.allProduct);
} else if (model.isLoading) {
content = Center(
child: CircularProgressIndicator(),
);
}
return RefreshIndicator(
child: content,
onRefresh: model.fetchProducts,
backgroundColor: Colors.blue,
color: Colors.red);
}
@override
Widget build(BuildContext context) {
return ScopedModelDescendant<MainModel>(
builder: (BuildContext context, Widget child, MainModel model) {
return _productLogic(model);
});
}
最佳答案
实际上,您必须将Global Key 设置为RefreshIndicator
并检查currentState
,如下所示
final GlobalKey<RefreshIndicatorState> _refreshKey =
new GlobalKey<RefreshIndicatorState>();
然后
return RefreshIndicator(
key: _refreshKey,
然后
_refreshKey.currentState?.show()?.then((_) {......
关于dart - 如何检查 RefreshIndicator 状态以根据其状态值采取行动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53940661/