requestLoading method

Future<void>? requestLoading({
  1. bool needMove = true,
  2. Duration duration = const Duration(milliseconds: 300),
  3. Curve curve = Curves.linear,
})

make the footer enter loading state,and callback onLoading

Implementation

Future<void>? requestLoading(
    {bool needMove = true,
    Duration duration = const Duration(milliseconds: 300),
    Curve curve = Curves.linear}) {
  assert(position != null,
      'Try not to call requestLoading() before build,please call after the ui was rendered');
  if (isLoading) return Future.value();
  StatefulElement? indicatorElement =
      _findIndicator(position!.context.storageContext, LoadIndicator);
  if (indicatorElement == null) return null;
  (indicatorElement.state as LoadIndicatorState).floating = true;
  if (needMove)
    SmartRefresher.ofState(position!.context.storageContext)
        ?.setCanDrag(false);
  if (needMove) {
    return Future.delayed(const Duration(milliseconds: 50)).then((_) async {
      await position
          ?.animateTo(position!.maxScrollExtent,
              duration: duration, curve: curve)
          .then((_) {
        SmartRefresher.ofState(position!.context.storageContext)
            ?.setCanDrag(true);
        footerMode!.value = LoadStatus.loading;
      });
    });
  } else {
    return Future.value().then((_) {
      footerMode!.value = LoadStatus.loading;
    });
  }
}