takeUnless method

T? takeUnless(
  1. bool condition
)

Returns this value if condition is false, otherwise null.

The opposite of takeIf. Useful for negated conditions.

Example:

final notEmpty = text.takeUnless(text.isEmpty);
// Returns text if it's not empty, null if empty

Implementation

T? takeUnless(bool condition) {
  if (!condition) return this;

  return null;
}