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().
Signature
Section titled “Signature”StringValidator<String?> string({String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| 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.
Code generation
Section titled “Code generation”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().
Example
Section titled “Example”final name = l.string();required String name, // l.string().required()String? nickname, // l.string()required Uri homepage, // l.string().required()name.validate(input)+2-1- valid:
'Ada' - valid:
null - invalid:
42
Lengths in .min(), .max() and .length() count UTF-16 code units, like String.length.