prepend method Null safety

String? prepend(
  1. String prefix
)

Prepends a prefix to the String

Example

String foo = 'world';
String newFoo = foo1.prepend('hello '); // returns 'hello world'

Implementation

String? prepend(String prefix) {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return this;
  }
  return prefix + this!;
}