LyricPainter constructor

LyricPainter(
  1. List<Lyric> lyrics,
  2. {List<Lyric> remarkLyrics,
  3. double currDuration,
  4. TickerProvider vsync,
  5. TextStyle lyricStyle,
  6. TextStyle remarkStyle,
  7. TextStyle currLyricStyle,
  8. double lyricGapValue,
  9. double subLyricGapValue,
  10. double lyricMaxWidth}
)

Implementation

LyricPainter(this.lyrics,
    {List<Lyric> remarkLyrics,
    double currDuration,
    TickerProvider vsync,
    TextStyle lyricStyle,
    TextStyle remarkStyle,
    TextStyle currLyricStyle,
    this.lyricGapValue,
    this.subLyricGapValue,
    this.lyricMaxWidth})
    : this.lyricTextStyle =
          lyricStyle ?? TextStyle(color: Colors.grey, fontSize: 13),
      this.subLyricTextStyle =
          remarkStyle ?? TextStyle(color: Colors.black, fontSize: 14),
      this.currLyricTextStyle =
          currLyricStyle ?? TextStyle(color: Colors.red, fontSize: 20),
      this.subLyrics = remarkLyrics {
  //歌词转画笔
  lyricTextPaints.addAll(lyrics
      .map(
        (l) => TextPainter(
            text: TextSpan(text: l.lyric, style: lyricTextStyle),
            textDirection: TextDirection.ltr),
      )
      .toList());

  //翻译/音译歌词转画笔
  if (subLyrics != null && subLyrics.isNotEmpty) {
    subLyricTextPaints.addAll(subLyrics
        .map((l) => TextPainter(
            text: TextSpan(text: l.lyric, style: subLyricTextStyle),
            textDirection: TextDirection.ltr))
        .toList());
    //因空行高度与非空行高度不一致,先存一个非空行的位置
    notEmptySubLyricIndex = getNotEmptyLineHeight(subLyrics);
    //计算默认歌词高度
    subLyricTextPaints[notEmptySubLyricIndex]
      ..layout(maxWidth: lyricMaxWidth);
    _subLyricHeight = subLyricTextPaints[notEmptySubLyricIndex].height;
  }

  currentLyricIndex = findLyricIndexByDuration(currDuration ?? 0, lyrics);
  if (currentLyricIndex == 0 || vsync == null) {
    offset = -computeScrollY(currentLyricIndex);
  } else {
    animationScrollY(currentLyricIndex, vsync);
  }
}