Skip to content

l.nullValue()

Passes only when the value is null. Returns a NullValidator, which has withName() and nothing else: a required value can never be null, and a custom validator would never be called.

NullValidator nullValue({String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
message String? Replaces the default error message.
messageBuilder MessageBuilder? Builds the message from the issue. message wins when both are given. See Message builders.

Code invalidType. Default message: value must be null. value is replaced by the field name when there is one.

A parameter of type Null maps to l.nullValue(). json_serializable and freezed cannot serialize a Null-typed field, so use it with dart_mappable or a hand-written fromJson. @WithCustomValidator on a Null field fails generation.

final cleared = l.nullValue();
cleared.validate(input)+1-1
  1. valid: null
  2. invalid: 1value must be null