animationScrollY method
dynamic
animationScrollY(
- dynamic currentLyricIndex,
- TickerProvider tickerProvider
)
Implementation
animationScrollY(currentLyricIndex, TickerProvider tickerProvider) {
var animationController = widget.controller.animationController;
if (animationController != null) {
animationController.stop();
}
animationController = AnimationController(
vsync: tickerProvider, duration: Duration(milliseconds: 300))
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
animationController!.dispose();
animationController = null;
}
});
// 计算当前行偏移量
var currentRowOffset = computeScrollY(currentLyricIndex);
//如果偏移量相同不执行动画
if (currentRowOffset == widget.controller.previousRowOffset) {
return;
}
// 起始为上一行,结束点为当前行
Animation animation = Tween<double>(
begin: widget.controller.previousRowOffset, end: currentRowOffset)
.animate(animationController!);
widget.controller.previousRowOffset = currentRowOffset;
animationController!.addListener(() {
_lyricPainter!.offset = -animation.value;
});
animationController!.forward();
}