getSpanList method

List<LyricSpanInfo> getSpanList(
  1. String realLyrics
)

get line span info list

Implementation

List<LyricSpanInfo> getSpanList(String realLyrics) {
  var invalidLength = 0;
  var startIndex = 0;
  var spanList = qrcPattern.allMatches(realLyrics).map((element) {
    var span = LyricSpanInfo();

    span.raw =
        realLyrics.substring(startIndex + invalidLength, element.start);

    var elementText = element.group(0) ?? "";
    span.index = startIndex;
    span.length = element.start - span.index - invalidLength;
    invalidLength += elementText.length;
    startIndex += span.length;

    var time = (element.group(1)?.split(",") ?? ["0", "0"]);
    span.start = int.parse(time[0]);
    span.duration = int.parse(time[1]);
    return span;
  }).toList();
  return spanList;
}