parsePicks function
1,3 or 2 as zero-based indexes below count; empty for anything
unreadable or out of range.
Implementation
List<int> parsePicks(String text, int count, {bool many = false}) {
final picks = <int>[];
for (final part in text.split(RegExp(r'[,\s]+'))) {
if (part.isEmpty) {
continue;
}
final n = int.tryParse(part);
if (n == null || n < 1 || n > count) {
return const [];
}
if (!picks.contains(n - 1)) {
picks.add(n - 1);
}
}
return many || picks.length <= 1 ? picks : const [];
}