You can now run the generator, and then override and implement the . Note that the "validate" method of the contentValidation is automatically generated, and you should never override it (Your IDE's Quick Fix won't override it neither).
Complete Example
// ... Imports & Part statements
@Modddel(
validationSteps: [
ValidationStep([
contentValidation,
]),
ValidationStep([
Validation('blackList', FailureType<PersonBlackListFailure>()),
])
],
)
class Person extends SimpleEntity<InvalidPerson, ValidPerson> with _$Person {
Person._();
factory Person({
required Age age,
required FullName name,
}) {
return _$Person._create(age: age, name: name);
}
@override
Option<PersonBlackListFailure> validateBlackList(person) {
/// Notice how we can directly access the fields of `age` and `name`,
/// because at this point they are ValidModddels.
if (person.name.firstName == 'Dash' &&
person.name.lastName == 'Birdy' &&
person.age.value == 28) {
return some(const PersonBlackListFailure.blackListed());
}
return none();
}
}
@freezed
class PersonBlackListFailure extends ValueFailure
with _$PersonBlackListFailure {
const factory PersonBlackListFailure.blackListed() = _BlackListed;
}