ifEmpty method Null safety

String? ifEmpty(
  1. Function act
)

If the provided string is empty do something.

Example

String foo = ''
foo.ifEmpty(()=>print('String is empty'));

Implementation

String? ifEmpty(Function act) {
  if (this == null) {
    return null;
  }

  return this!.isEmpty ? act() : this;
}