setScrollPosition method

void setScrollPosition(
  1. int currentIndex
)

Implementation

void setScrollPosition(int currentIndex) {
  final selectedItemOffset = _setSelectedItemPosition();
  double scrollPosition = (dropdownItemOptions.height * currentIndex) +
      (dropdownOptions.gap.betweenItems * currentIndex) -
      selectedItemOffset;
  final overScrollPosition = scrollController.position.maxScrollExtent;
  if (overScrollPosition < scrollPosition) {
    scrollPosition = overScrollPosition;
  } else if (scrollPosition < 0) {
    scrollPosition = 0;
  }
  if (_totalHeight < dropdownHeight) {
    scrollPosition = 0;
  }
  scrollController.animateTo(scrollPosition,
      duration: dropdownOptions.duration, curve: dropdownOptions.curve);
}