How to hide RefreshProgressIndicator after onRefresh is called in RefreshIndicator

Viewed 16

In my network function I use showDialog() to show progress dialog when the network call is happening, but I also need the RefreshIndicator to have the pull-to-refresh.

When I pull down on ListView, the RefreshProgressIndicator is shown, and when I let go, the onRefresh method is called which loads my networkCall function which shows my own progress dialog, and the RefreshProgressIndicator is still loading behind the progress dialog, which is expected.

So is there a way to hide/stop the RefreshProgressIndicator so that it is not loading behind the my progress dialog?

Future<void> networkCall() async {
   showDialog();
   await apiCall();
   hideDialog();
   setState((){...}):
}

RefreshIndicator(
   onRefresh: networkCall,
   child: ListView.builder(),
)

I need my own showDialog() to show the loading process. So how do I hide the RefreshProgressIndicator when onRefresh is called?

1 Answers

from the documentation said that we have to return Future.delayed.zero to avoid the spinner never go away.

and i think you can use this logic.

Future<void> networkCall() async {
  // add this to dissmis the spinner
   Future.delayed(const Duration(seconds: 0)); // spinner will go away immediately

   showDialog();

  // you can use await or then,whatever you want.
   apiCall().then((value){ 
   hideDialog();
  });
   setState((){...}):
}
Related