refresh method

Future<void> refresh([
  1. FutureVoidCallback? refreshCallback
])

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(widget.completeDuration, () {
        if (!mounted) {
          return;
        }
        setState(() {
          _stage = TriggerStage.idle;
          _currentExtent = 0;
        });
      });
    });
  });
}