computeScrollY method

double computeScrollY(
  1. int curLine
)

计算传入行和第一行的偏移量

Implementation

double computeScrollY(int curLine) {
  double totalHeight = 0;
  for (var i = 0; i < curLine; i++) {
    var currPaint = lyricTextPaints[i]
      ..text = TextSpan(text: lyrics[i].lyric, style: lyricStyle);
    currPaint.layout(maxWidth: lyricMaxWidth!);
    totalHeight += currPaint.height + widget.lyricGap;
  }
  if (remarkLyrics != null) {
    //增加 当前行之前的翻译歌词的偏移量
    remarkLyrics!
        .where((subLyric) => subLyric.endTime! <= lyrics[curLine].endTime!)
        .toList()
        .forEach((subLyric) {
      var currentPaint = subLyricTextPaints[remarkLyrics!.indexOf(subLyric)]
        ..text = TextSpan(text: subLyric.lyric, style: remarkStyle);
      currentPaint.layout(maxWidth: lyricMaxWidth!);
      totalHeight += widget.remarkLyricGap + currentPaint.height;
    });
  }
  return totalHeight;
}