setScrollPosition method
void
setScrollPosition(
- int currentIndex
)
Implementation
void setScrollPosition(int currentIndex) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await animationForward();
if (currentIndex != -1) {
double totalHeight = widget.dropdownList.length *
(widget.dropdownItemHeight + widget.dropdownItemGap) +
widget.dropdownItemTopGap +
widget.dropdownItemBottomGap;
double scrollPosition = currentIndex *
(widget.dropdownItemHeight + widget.dropdownItemGap) +
widget.dropdownItemTopGap -
widget.dropdownItemGap;
double overScrollPosition = ((widget.dropdownItemHeight *
widget.dropdownList.length) +
(widget.dropdownItemGap * (widget.dropdownList.length - 1)) +
widget.dropdownItemTopGap) -
widget.dropdownHeight +
widget.dropdownItemBottomGap;
if (currentIndex == 0) {
scrollPosition = 0;
}
if (overScrollPosition < scrollPosition) {
scrollPosition = overScrollPosition;
}
if (totalHeight < widget.dropdownHeight) {
scrollPosition = 0;
}
_scrollController.animateTo(scrollPosition,
duration: au.isAnimation(
status: widget.isAnimation,
duration: Duration(milliseconds: 300)),
curve: Curves.easeInOut);
setState(() {
widget.dropdownIsSelected[currentIndex] = true;
});
_DCController[currentIndex].forward();
_paddingController[currentIndex].forward();
}
});
}