animateToOffset method

  1. @override
Future animateToOffset({
  1. required double offset,
  2. required IndicatorMode mode,
  3. Duration? duration,
  4. Curve curve = Curves.linear,
  5. bool jumpToEdge = true,
  6. ScrollController? scrollController,
})
override

Animates the position from its current value to the given value. offset The offset to scroll to. mode When duration is null and clamping is true, set the state. jumpToEdge Whether to jump to the edge before scrolling. duration See ScrollPosition.animateTo. curve See ScrollPosition.animateTo. scrollController When position is not ScrollPosition, you can use ScrollController.

Implementation

@override
Future animateToOffset({
  required double offset,
  required IndicatorMode mode,
  Duration? duration,
  Curve curve = Curves.linear,
  bool jumpToEdge = true,
  ScrollController? scrollController,
}) async {
  try {
    if (scrollController == null && _position is! ScrollPosition) {
      return;
    }
  } catch (_) {
    return;
  }
  final scrollTo = position.maxScrollExtent + offset;
  _releaseOffset = offset;
  if (jumpToEdge) {
    if (scrollController != null) {
      scrollController
          .jumpTo(scrollController.positions.first.maxScrollExtent);
    } else {
      (_position as ScrollPosition).jumpTo(position.maxScrollExtent);
    }
  }
  if (clamping) {
    if (duration == null) {
      _offset = offset;
      _mode = mode;
      _updateBySimulation(position, 0);
    } else {
      userOffsetNotifier.value = true;
      _clampingAnimationController!.value = position.maxScrollExtent;
      await _clampingAnimationController!
          .animateTo(scrollTo, duration: duration, curve: curve);
      userOffsetNotifier.value = false;
      _updateBySimulation(position, 0);
    }
  } else {
    if (_position is ScrollPosition) {
      if (duration == null) {
        if (scrollController != null) {
          scrollController.jumpTo(scrollTo);
        } else {
          (_position as ScrollPosition).jumpTo(scrollTo);
        }
      } else {
        userOffsetNotifier.value = true;
        if (scrollController != null) {
          await scrollController.animateTo(scrollTo,
              duration: duration, curve: curve);
        } else {
          await (_position as ScrollPosition)
              .animateTo(scrollTo, duration: duration, curve: curve);
        }
        userOffsetNotifier.value = false;
        notifyListeners();
      }
    }
  }
}