maybeStartSnapAnimation method

void maybeStartSnapAnimation (ScrollDirection direction)

If the header isn't already fully exposed, then scroll it into view.

Implementation

void maybeStartSnapAnimation(ScrollDirection direction) {
  if (snapConfiguration == null)
    return;
  if (direction == ScrollDirection.forward && _effectiveScrollOffset <= 0.0)
    return;
  if (direction == ScrollDirection.reverse && _effectiveScrollOffset >= maxExtent)
    return;

  final TickerProvider vsync = snapConfiguration.vsync;
  final Duration duration = snapConfiguration.duration;
  _controller ??= AnimationController(vsync: vsync, duration: duration)
    ..addListener(() {
      if (_effectiveScrollOffset == _animation.value)
        return;
      _effectiveScrollOffset = _animation.value;
      markNeedsLayout();
    });

  _animation = _controller.drive(
    Tween<double>(
      begin: _effectiveScrollOffset,
      end: direction == ScrollDirection.forward ? 0.0 : maxExtent,
    ).chain(CurveTween(
      curve: snapConfiguration.curve,
    )),
  );

  _controller.forward(from: 0.0);
}