controller property

  1. @override
ScrollController controller
override

The created ScrollController

Implementation

@override
ScrollController get controller {
  if (_controller != null) {
    return _controller!;
  }
  _controller = ScrollController(
    initialScrollOffset: initialScrollOffset,
    keepScrollOffset: keepScrollOffset,
  );
  // _removeFromInjectedList = addToInjectedModels(this);
  Timer? _timer;
  hasReachedMinExtent = initialScrollOffset == 0.0;
  void setFlags() {
    hasStartedScrolling = false;
    hasStartedScrollingForward = false;
    hasStartedScrollingReverse = false;
    hasEndedScrolling = false;
    if (_userScrollDirection != position.userScrollDirection) {
      _userScrollDirection = position.userScrollDirection;
      if (position.userScrollDirection == ScrollDirection.forward) {
        hasStartedScrollingForward = true;
      } else if (position.userScrollDirection == ScrollDirection.reverse) {
        hasStartedScrollingReverse = true;
      }
    }
    if (_controller!.offset >= position.maxScrollExtent &&
        !position.outOfRange) {
      hasReachedMinExtent = false;
      hasReachedMaxExtent = true;
      SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
        if (_controller == null) {
          return;
        }
        if (_maxScrollExtent != position.maxScrollExtent) {
          _maxScrollExtent = position.maxScrollExtent;
          _setState();
        }
      });
    } else if (_controller!.offset <= position.minScrollExtent &&
        !position.outOfRange) {
      hasReachedMinExtent = true;
      hasReachedMaxExtent = false;
    } else {
      hasReachedMinExtent = false;
      hasReachedMaxExtent = false;
    }

    if (_timer == null) {
      if (position.userScrollDirection != ScrollDirection.idle) {
        hasStartedScrolling = true;
        isScrolling = true;
      }
      hasEndedScrolling = false;
    }
    _timer?.cancel();
    _timer = Timer(
      Duration(milliseconds: onScrollEndedDelay),
      () {
        if (isScrolling) {
          hasEndedScrolling = true;
        }

        hasStartedScrolling = false;
        isScrolling = false;
        _userScrollDirection = null;
        hasReachedMaxExtent = false;
        hasReachedMinExtent = false;
        onScroll?.call(this);
        _timer = null;
        notify();
      },
    );
  }

  _controller!.addListener(
    () {
      _maxScrollExtent = position.maxScrollExtent;
      setFlags();
      onScroll?.call(this);
      _setState();
    },
  );

  return _controller!;
}