onEmpty method
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;