requestLoading method

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

手动触发上拉加载更多

参数

  • needMove:是否需要动画滚动到加载位置,默认为 true
  • needCallback:是否需要调用 onLoading 回调,默认为 true
  • duration:动画持续时间,默认为 300 毫秒
  • curve:动画曲线,默认为 Curves.linear

返回值

  • Future

使用示例

_refreshController.requestLoading();

Implementation

Future<void>? requestLoading(
    {bool needMove = true,
    bool needCallback = true,
    Duration duration = const Duration(milliseconds: 300),
    Curve curve = Curves.linear}) {
  assert(position != null, '请不要在构建完成前调用 requestLoading(),请在 UI 渲染后调用');
  if (isLoading) return Future.value();

  StatefulElement? indicatorElement = _findIndicator(position!.context.storageContext, LoadIndicator);
  if (indicatorElement == null || _refresherState == null) return null;

  (indicatorElement.state as LoadIndicatorState).floating = true;

  if (needMove && _refresherState!.mounted) {
    _refresherState!.setCanDrag(false);
  }

  if (needMove) {
    return Future.delayed(const Duration(milliseconds: 50)).then((_) async {
      await position?.animateTo(position!.maxScrollExtent, duration: duration, curve: curve).then((_) {
        if (_refresherState != null && _refresherState!.mounted) {
          _refresherState!.setCanDrag(true);
          if (needCallback) {
            footerMode!.value = LoadStatus.loading;
          } else {
            footerMode!.setValueWithNoNotify(LoadStatus.loading);
            if (indicatorElement.state.mounted) {
              (indicatorElement.state as LoadIndicatorState).setState(() {});
            }
          }
        }
      });
    });
  } else {
    return Future.value().then((_) {
      footerMode!.value = LoadStatus.loading;
    });
  }
}