createKey static method

String createKey(
  1. String input
)

Implementation

static String createKey(String input) {
  if (input.trim().isEmpty) return '';

  // Normalize common apostrophes so contractions don't split into two words.
  // e.g. "don't" -> "dont", "you’re" -> "youre"
  var normalized = input
      .replaceAll("'", '')
      .replaceAll('’', '') // unicode right single quote
      .trim();

  // Replace any remaining non-alphanumeric (except space) with a space
  String cleaned = normalized.replaceAll(RegExp(r'[^A-Za-z0-9 ]'), ' ').trim();

  // Split into words
  List<String> parts = cleaned.split(RegExp(r'\s+'));
  parts = parts.where((e) => e.isNotEmpty).toList();
  if (parts.isEmpty) return '';

  // camelCase: first word lowercase, rest Capitalized
  final first = parts.first.toLowerCase();
  final rest = parts.skip(1).map(
        (w) => w.substring(0, 1).toUpperCase() + w.substring(1).toLowerCase(),
  );

  String key = ([first, ...rest]).join();

  // Prevent Dart keyword conflicts
  if (dartReservedKeywords.contains(key)) {
    key = '${key}Key';
  }

  return key;
}