Modddels
HomeGithubPub.dev
v0.1
v0.1
  • Motivation
  • Setup
  • Generalities
    • Modddels Overview
    • Validations & Validation steps
    • Structure of a Modddel
    • Member parameters & Dependency parameters
    • Usage
      • Data equality & toString
      • Pattern matching
      • Reading the fields
      • Reading the failures
      • CopyWith
  • ValueObjects
    • ValueObjects Overview
    • Creating a ValueObject
  • Entities
    • Entities Overview
    • ContentValidation & ContentFailure
    • ValidationSteps in Entities
    • SimpleEntity
      • Creating a SimpleEntity
      • Special Cases
    • IterableEntity & Iterable2Entity
      • IterableEntity / Iterable2Entity kinds
      • The Type Template
      • Creating an IterableEntity / Iterable2Entity
      • InvalidMembers Description
      • Special Cases
      • Creating your own IterableEntity / Iterable2Entity kind
  • Advanced Notions
    • The NullFailure Annotation
    • Using multiple parameters annotations
    • Class Hierarchy of ValueObjects
    • Class Hierarchy of Entities
    • Models that are always valid / invalid
  • Union of Modddels
    • Union of Modddels Overview
    • Basic Usage
    • Case-modddels pattern matching
    • Default Factory Constructor
    • Shared Properties
    • The Validate Methods
    • CopyWith
  • Unit-Testing Of Modddels
    • Unit-Testing Overview
    • Available Tests
    • Customizing Tests
  • Additional Information
    • Using type aliases
    • Re-running the generator
    • All Available Modddels
    • VsCode Snippets
Powered by GitBook
On this page
  • For IterableEntity
  • For Iterable2Entity
  1. Entities
  2. IterableEntity & Iterable2Entity

InvalidMembers Description

PreviousCreating an IterableEntity / Iterable2EntityNextSpecial Cases

Last updated 1 year ago

the ContentFailure holds a list : List<ModddelInvalidMember> invalidMembers, where ModddelInvalidMember is a wrapper class that holds an invalid modddel and its description. This description is used in the toString method of the ContentFailure. It varies depending on the entity kind.

For IterableEntity

The description is by default "item $index", except for the MappedKeys/MappedValues kinds where it's "entry $index".

As we know already, the collection of an IterableEntity can be converted to an iterable. The index that we talk about here is the index of a modddel in that iterable.

You can customize the description for any IterableEntity by overriding the $description method.

For example : Let's say we have a BookList ListEntity that holds a list of books.

// Inside your `BookList` class :
@override
String $description(int index) => 'Book number ${index + 1}';

You can also optionally override the $descriptionDetails method. This method has two parameters : the modddel that is held inside the collection and its index. It returns a string that will be appended to the description, in parenthesis.

In our example :

// Inside your `BookList` class :
String? $descriptionDetails(BaseModddel modddel, int index) =>
    'id = ${(modddel as Book).id}';

// Example of a full description : "Book number 1 (id = 1234)"

You can cast the modddel to whatever type the modddel held inside the collection is.

For example : If you have a ListEntity that holds a list of Book, you can safely cast modddel like so :

String? $descriptionDetails(BaseModddel modddel, int index) {
  final casted = modddel as Book;
  // ...
}

If you have a ListEntity that is a where one case-modddel holds a list of Book, and the other case-modddel holds a list of Article, you can do :

String? $descriptionDetails(BaseModddel modddel, int index) {
  if(modddel is Book) {
    // ...
  }
  else {
    final casted = modddel as Article;
    // ...
  } 
}

For Iterable2Entity

The collection of an Iterable2Entity can be converted to two iterables of modddels. Therefore, there are two descriptions, one for each iterable.

By default :

  • The description of the modddels of the first iterable is "first $index", except for the Map kinds (MapEntity...) where it's "key $index".

  • The description of the modddels of the second iterable is "second $index", except for the Map kinds (MapEntity...) where it's "value $index".

You can customize these descriptions by overriding respectively the $description1 and $description2 methods.

You can also optionally override the $descriptionDetails1 and $descriptionDetails2 methods.

union of modddels
As explained previously,