updateActiveCueLists method

Future<void> updateActiveCueLists()

will make sure the cuelists are populated then will ask for all the active ones

Implementation

Future<void> updateActiveCueLists() async {
  if (cueLists.isEmpty) await loadCueLists();
  if (cueLists.isEmpty) return;
  var res = await getActiveCueLists();

  // we only need the cue numbers
  List<int> foundNumbers = [];
  if (res == null) return;
  for (var line in res.dataLines) {
    if (line.isEmpty) continue;
    if (line.startsWith('No')) continue;

    _dbg(line);
    try {
      var cueList = OnyxCueList.fromLine(this, line);
      if (cueList.cueListNumber == 0) continue;
      foundNumbers.add(cueList.cueListNumber);
    } on FormatException catch (e) {
      _dbg(e);
      continue;
    }
  }

  for (var cueList in cueLists) {
    var isActive = foundNumbers.contains(cueList.cueListNumber);
    var wasActive = cueList.active;
    if ((isActive && !wasActive) || (!isActive && wasActive)) {
      cueList.transitioning = false;
      cueList.active = isActive;
    }
  }
  _notify();
}