mapIfEmpty method

String mapIfEmpty(
  1. String str
)

Returns this string if it has a value, otherwise returns the provided str.

This method provides a default value when the string is null or empty.

Example:

String? name;
print(name.mapIfEmpty('Unknown')); // prints: Unknown

Implementation

String mapIfEmpty(String str) {
  return isNullOrEmpty ? str : this!;
}