Modddels
HomeGithubPub.dev
v0.2
v0.2
  • 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
  1. Generalities

Usage

PreviousMember parameters & Dependency parametersNextData equality & toString

In this section, we'll dive deeper into the usage of modddels.

Let's create an instance of our modddel :

// NB : In this section's examples, the types of the variables is specified only
// for the sake of showing their types to you. You don't need to do so.

final Username username = Username(value: 'dash');

Here are a few utilities you can use :

// You can quickly verify if a modddel is valid using [isValid]
bool isValid = username.isValid;

// You can convert the modddel to an Either using [toEither] or [toBroadEither]
Either<InvalidUsername, ValidUsername> either = username.toEither;

Either<List<Failure>, ValidUsername> broadEither = username.toBroadEither;

You can explore more utilities in the next subpages :

Data equality & toString
Pattern matching
Reading the fields
Reading the failures
CopyWith