reverse method Null safety

String? reverse()

Returns the String reversed.

Example

String foo = 'Hello World';
String reversed = foo.reverse() ; // returns 'dlrow olleH'

Implementation

String? reverse() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return this;
  }
  var letters = this!.split('').toList().reversed;
  return letters.reduce((current, next) => current + next);
}