Creating a SimpleEntity

Steps to create a SimpleEntity

Declare your class this way :

class Person extends SimpleEntity<InvalidPerson, ValidPerson> with _$Person {}

Add the imports and part statements, the @Modddel annotation (don't forget including the contentValidation), and the private empty constructor.

Add the factory constructor. The member parameters of the factory constructor should all be modddels.

factory Person({
  required FullName name,
  required Age age,
}) //...

Create your failure(s) sealed class(es).

You can now run the generator, and then override and implement the "validate" methods. 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 

  validationSteps: [
      Validation('blackList', FailureType<PersonBlackListFailure>()),
class Person extends SimpleEntity<InvalidPerson, ValidPerson> with _$Person {

  factory Person({
    required Age age,
    required FullName name,
  }) {
    return _$Person._create(age: age, name: name);

  Option<PersonBlackListFailure> validateBlackList(person) {
    /// Notice how we can directly access the fields of `age` and `name`,
    /// because at this point they are ValidModddels.
    if ( == 'Dash' && == 'Birdy' &&
        person.age.value == 28) {
      return some(const PersonBlackListFailure.blackListed());
    return none();

class PersonBlackListFailure extends ValueFailure
    with _$PersonBlackListFailure {
  const factory PersonBlackListFailure.blackListed() = _BlackListed;