requestRefresh method
make the header enter refreshing state,and callback onRefresh
Implementation
Future<void>? requestRefresh(
{bool needMove = true,
Duration duration = const Duration(milliseconds: 500),
Curve curve = Curves.linear}) {
assert(position != null,
'Try not to call requestRefresh() before build,please call after the ui was rendered');
if (isRefresh) return Future.value();
StatefulElement? indicatorElement =
_findIndicator(position!.context.storageContext, RefreshIndicator);
if (indicatorElement == null) return null;
(indicatorElement.state as RefreshIndicatorState).floating = true;
if (needMove)
SmartRefresher.ofState(position!.context.storageContext)
?.setCanDrag(false);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (needMove) {
Future.delayed(const Duration(milliseconds: 50)).then((_) async {
// - 0.0001 is for NestedScrollView.
await position
?.animateTo(position!.minScrollExtent - 0.0001,
duration: duration, curve: curve)
.then((_) {
SmartRefresher.ofState(position!.context.storageContext)
?.setCanDrag(true);
headerMode!.value = RefreshStatus.refreshing;
});
});
} else {
Future.value().then((_) {
headerMode!.value = RefreshStatus.refreshing;
});
}
});
return Future.value();
}