File tree Expand file tree Collapse file tree
packages/dart_mappable/doc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -127,6 +127,25 @@ void main() {
127127}
128128```
129129
130+ ## Multiple Constructors
131+
132+ You can also use factory constructors on the base class to provide a more convenient API for creating instances.
133+
134+ ``` dart
135+ // Set the discriminator key to "type".
136+ @MappableClass(discriminatorKey: 'type')
137+ abstract class Animal with AnimalMappable {
138+ const Animal(this.name);
139+
140+ // Factory constructors pointing to subclasses
141+ const factory Animal.nullAnimal(String name) = NullAnimal;
142+
143+ const factory Animal.defaultAnimal(String name, String type) = DefaultAnimal;
144+
145+ final String name;
146+ }
147+ ```
148+
130149## Custom Discriminator Logic
131150
132151For a more advanced use-case where the discriminator key/value system is not enough, you can also
You can’t perform that action at this time.
0 commit comments