gpt4 book ai didi

dart - 如何检查 RefreshIndicator 状态以根据其状态值采取行动?

转载 作者:IT王子 更新时间:2023-10-29 07:05:20 26 4
gpt4 key购买 nike

我的意思是检查刷新指示器是否正在刷新。根据该值采取行动以在该值为真时停止 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);
});
}

enter image description here

最佳答案

实际上,您必须将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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com