refresh method
Triggers a refresh programmatically.
Initiates the refresh animation and invokes the provided callback or
widget's onRefresh callback. Can be called from parent widgets to
trigger refresh without user gesture.
Parameters:
refreshCallback: Optional callback to use instead of widget's onRefresh
Returns a Future that completes when refresh finishes.
Implementation
Future<void> refresh([FutureVoidCallback? refreshCallback]) async {
_scrolling = false;
int count = ++_currentFutureCount;
if (_currentFuture != null) {
await _currentFuture;
}
setState(() {
_currentFuture = _refresh(refreshCallback);
});
return _currentFuture!.whenComplete(() {
if (!mounted || count != _currentFutureCount) {
return;
}
setState(() {
_currentFuture = null;
_stage = TriggerStage.completed;
// Future.delayed works the same
Timer(_completeDuration, () {
if (!mounted) {
return;
}
setState(() {
_stage = TriggerStage.idle;
_currentExtent = 0;
});
});
});
});
}