Default Factory Constructor

You can have a "default" (unnamed) factory constructor along with other named factory constructors.

For example :

// @Modddel(...)
class User extends SimpleEntity<InvalidUser, ValidUser> with _$User {
  User._();

  /// (A)
  factory User({
    required Username username,
    required Age age,
  }) // { ... }

  /// (B)
  factory User.moderator({
    required Username username,
    required Age age,
    required Permissions permissions,
  }) // { ... }

  // ...
}

In this example, two case-modddels will be generated : DefaultUser for the "default" factory constructor (A), and Moderator for the other factory constructor (B).

Also, in the case-modddels pattern matching methods, the defaultUser callback parameter will be positional instead of being named :

user.mapUser(
  (defaultUser) {},
  moderator: (moderator) {},
);

Last updated