nullIfEmpty method
Returns null if the string is empty or contains only whitespace.
trimFirst: If true (default), the string is trimmed before the check.
Implementation
@useResult
String? nullIfEmpty({bool trimFirst = true}) {
if (isEmpty) {
return null;
}
if (trimFirst) {
final String trimmed = trim();
return trimmed.isEmpty ? null : trimmed;
}
return this;
}