orNull method

String? orNull()

Returns null if this string isBlank, otherwise returns the string itself. Useful for converting blank strings to null in forms.

''.orNull();         // null
'  '.orNull();       // null
'hello'.orNull();    // 'hello'

Implementation

String? orNull() => isBlank ? null : this;