如何检查RefreshIndicator状态以根据其状态值采取措施?

时间:2018-12-27 06:27:35

标签: dart flutter

我的意思是检查刷新指示器是否正在刷新。在该值为true时基于该值采取行动以阻止微调框旋转。

 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

1 个答案:

答案 0 :(得分:0)

实际上,您必须将全局密钥设置为RefreshIndicator并选中currentState,如下所示

  final GlobalKey<RefreshIndicatorState> _refreshKey =
      new GlobalKey<RefreshIndicatorState>();

然后

 return RefreshIndicator(
        key: _refreshKey,

然后

_refreshKey.currentState?.show()?.then((_) {......
相关问题