As explained previously, 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 :@overrideString$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 = ${(modddelasBook).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 :
If you have a ListEntity that is a union of modddels where one case-modddel holds a list of Book, and the other case-modddel holds a list of Article, you can do :