capitalize method Null safety

String? capitalize()

Capitalizes the string in normal form.

Example

String foo = 'hAckErrR';
String cFoo = foo.capitalize(); // returns 'Hackerrr'.

Implementation

String? capitalize() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return this;
  }
  return '${this![0].toUpperCase()}${this!.substring(1).toLowerCase()}';
}