Skip to content

.withName()

Returns a copy of the validator whose default messages start with name instead of value. It matters only when the validator validates a value directly; inside a schema, the field key is the field name and withName is ignored.

Self withName(String? name)
Parameter Type Meaning
name String? The field name, or null to clear it.

Code none. Default message: withName adds no validation. It changes the fieldName of every issue the validator produces, and so the value prefix of default messages.

Every generated schema ends in .withName('ModelName'), which names the whole model in the must be a map message when $ModelValidate receives something that is not a map.

final email = l.string().email().withName('email');
l.string().email().withName('email').validate(input)+0-1
  1. invalid: 'bad'email must be a valid email address

Inside a schema the key wins:

{contact: [contact must be a valid email address]}