coalesce<T> method

T coalesce<T>(
  1. T defaultValue
)

replace null with default value

Implementation

T coalesce<T>(T defaultValue) {
  if (this is String) {
    String? str = this;
    return (str ?? "").isEmpty ? defaultValue : this;
  }
  return this == null ? defaultValue : this;
}