validateKey static method

String? validateKey(
  1. String value, {
  2. required Set<String> taken,
  3. required String what,
})

Rejects a key that is unusable or already taken, for Prompt.text.

Returns the message to show, or null when the key is fine.

Implementation

static String? validateKey(
  String value, {
  required Set<String> taken,
  required String what,
}) {
  if (!RegExp(r'^[A-Za-z0-9_-]+$').hasMatch(value)) {
    return 'a $what key may only contain letters, digits, "_" and "-"';
  }
  if (taken.contains(value)) return 'that $what key is already used';
  return null;
}