.strict()
Returns a copy of the schema that fails when the input has a key the schema does not declare. Each unknown key produces one unrecognizedKey issue at that key’s path, with params['key']. Only SchemaValidator has this method.
Signature
Section titled “Signature”SchemaValidator<O> strict({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 unrecognizedKey. Default message: role is not an allowed key, where role is the unknown key.
Code generation
Section titled “Code generation”The generator does not emit .strict(). Apply it to a generated schema where you use it: $UserSchema.strict().
Example
Section titled “Example”final user = l.schema({'name': l.string().required()}).strict();final result = $UserSchema.strict().validateSchema(json, fromJson: User.fromJson);l.schema({'name': l.string().required()}).strict().validate(input)+1-1- valid:
{'name': 'Ada'} - invalid:
{'name': 'Ada', 'role': 'admin'}