nextTableNumber function
The next table number over the live tables' numbers (T5): max + 1
over the counted ones, written without leading zeros; "1" when none
counts. When max + 1 would take nine digits, the smallest unused
positive integer instead, so a placement never makes a duplicate or an
invalid number.
Implementation
String nextTableNumber(Iterable<String> numbers) {
final used = <int>{};
var max = 0;
for (final n in numbers) {
final v = countedTableNumber(n.trim());
if (v == null) continue;
used.add(v);
if (v > max) max = v;
}
if (max < _kLargestCounted) return '${max + 1}';
var candidate = 1;
while (used.contains(candidate)) {
candidate++;
}
return '$candidate';
}