onEmpty method

String? onEmpty(
  1. String? val
)

Returns a provided alternative string val if the original string is empty. If val is null, it defaults to an empty string.

Example:

print(''.onEmpty('default')); // Output: 'default'
print('text'.onEmpty('default')); // Output: 'text'

Implementation

String? onEmpty(String? val) => isEmpty ? (val ?? '') : this;