tryParse static method

ChordPlayItem? tryParse(
  1. String key
)

Lê a chave de gravação (camada/trecho/etapa). null se a chave não é de um item desta trilha (camada ou etapa que não existem, trecho negativo ou sem a forma canônica).

Implementation

static ChordPlayItem? tryParse(String key) {
  final parts = key.split('/');
  if (parts.length != 3) return null;
  final layer = ChordPlayLayer.values.asNameMap()[parts[0]];
  final stage = MusicStage.values.asNameMap()[parts[2]];
  if (layer == null || stage == null || !kChordPlayStages.contains(stage)) {
    return null;
  }
  final int? section;
  if (parts[1] == kMusicWholeKey) {
    section = null;
  } else {
    final index = int.tryParse(parts[1]);
    if (index == null || index < 0) return null;
    section = index;
  }
  final item = ChordPlayItem(layer: layer, stage: stage, section: section);
  return item.key == key ? item : null;
}