toCamelCase static method

String toCamelCase(
  1. String text
)

Convert string to camelCase

text - The text to convert Returns camelCase string

Implementation

static String toCamelCase(String text) {
  if (text.isEmpty) return text;

  final words = text.toLowerCase().split(RegExp(r'[\s_-]+'));
  if (words.isEmpty) return text;

  String result = words[0];
  for (int i = 1; i < words.length; i++) {
    result += capitalizeFirst(words[i]);
  }

  return result;
}