toCamelCase method Null safety

String? toCamelCase()

Returns the String in camelcase.

Example

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

Implementation

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