animationScrollY method

dynamic animationScrollY (
  1. dynamic currentLyricIndex,
  2. TickerProvider tickerProvider
)

Implementation

animationScrollY(currentLyricIndex, TickerProvider tickerProvider) {
  if (currentLyricIndex != 0 && currentLyricIndex != _oldCurrentLyricIndex) {
    if (_animationController != null) {
      _animationController.stop();
    }
    _animationController = AnimationController(
        vsync: tickerProvider, duration: Duration(milliseconds: 200))
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          _animationController.dispose();
          _animationController = null;
        }
      });
    // 计算上一行偏移量
    var previousRowOffset = computeScrollY(currentLyricIndex - 1);
    // 计算当前行偏移量
    var currentRowOffset = computeScrollY(currentLyricIndex);
    // 起始为上一行,结束点为当前行
    Animation animation =
        Tween<double>(begin: previousRowOffset, end: currentRowOffset)
            .animate(_animationController);
    _animationController.addListener(() {
      offset = -animation.value;
    });
    _animationController.forward();
  }
  _oldCurrentLyricIndex = currentLyricIndex;
}