withOptionalProperty method

ObjectSchema withOptionalProperty(
  1. String name, [
  2. dynamic type,
  3. List<IValidationRule>? rules
])
inherited

Adds a validation schema for an optional object property.

  • name a property name.
  • type (optional) a property schema or type.
  • rules (optional) a list of property validation rules.

Implementation

ObjectSchema withOptionalProperty(String name,
    [dynamic type, List<IValidationRule>? rules]) {
  var schema = PropertySchema(name, type);
  if (rules != null) {
    schema.setRules(List.from(rules));
  }
  schema.makeOptional();

  return withProperty(schema);
}