scrollTo method

void scrollTo(
  1. double offset,
  2. int duration
)

Implementation

void scrollTo(double offset, int duration) {
  if (offset >= 0 && scrollController.hasClients) {
    // 预防滑动超出之后的异常回弹
    var finalOffset = offset < scrollController.position.maxScrollExtent
        ? offset
        : scrollController.position.maxScrollExtent;
    if (duration > 0) {
      scrollController.animateTo(
        finalOffset,
        duration: Duration(milliseconds: duration),
        curve: Curves.linearToEaseOut,
      );
    } else {
      scrollController.jumpTo(finalOffset);
    }
  }
}