trimAll property Null safety

String? trimAll

Trims leading and trailing spaces, so as extra spaces in between words.

Example

String text = '    esentis    thinks   ';
String trimmed = text.trimAll ; // returns 'esentis thinks'

Implementation

String? get trimAll {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return this;
  }
  return this!.trim().replaceAll(RegExp(' +'), ' ');
}