notationScreen function

String? notationScreen(
  1. String word,
  2. Iterable<String> screens
)

The screen of screens (ids, cook-mode) that word after a go names: its id, its id written with underscores or capitals (go cook_mode), or the one screen whose id starts with it or holds all its words (go cook); null when none or several do.

Implementation

String? notationScreen(String word, Iterable<String> screens) {
  if (screens.isEmpty || !RegExp(r'^[A-Za-z_][A-Za-z0-9_-]*$').hasMatch(word)) return null;
  final ids = screens.toList();
  if (ids.contains(word)) return word;
  final t = word.replaceAll('_', '-').toLowerCase();
  if (ids.contains(t)) return t;
  final words = t.split('-');
  final near = ids.where((p) => p.startsWith('$t-') || words.every(p.split('-').contains)).toList();
  return near.length == 1 ? near.first : null;
}