toCamelCase property

String? toCamelCase

Returns the String in camelcase.

Example

String foo = 'Find max of array';
String camelCase = foo.toCamelCase; // returns 'findMaxOfArray'

Implementation

String? get toCamelCase {
  if (this == null) return null;
  if (this!.isEmpty) return this;
  final words = this!.trim().split(RegExp(r'(\s+)'));
  final result = StringBuffer(words[0].toLowerCase());
  for (var i = 1; i < words.length; i++) {
    result.write(
      words[i].substring(0, 1).toUpperCase() +
          words[i].substring(1).toLowerCase(),
    );
  }
  return result.toString();
}