Skip to content

l.string()

Passes when the value is a String. Returns a StringValidator<String?>, which has every string modifier; .required() narrows the output to String. null passes until you add .required().

StringValidator<String?> string({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 a string, with params['expected'] set to 'string'. value is replaced by the field name when there is one.

A String parameter maps to l.string(); DateTime and Uri parameters map to l.string() with .dateTime() for DateTime. Non-nullable parameters without a default get .required().

final name = l.string();
name.validate(input)+2-1
  1. valid: 'Ada'
  2. valid: null
  3. invalid: 42value must be a string

Lengths in .min(), .max() and .length() count UTF-16 code units, like String.length.