ModelFactory<T extends Model> class
final
Model factory (named ModelFactory because ModelFactory is the container
binding typedef; BLUEPRINT_V2 §7.5.6).
final userFactory = ModelFactory<User>(
User.definition,
(f) => {'name': f.name(), 'email': f.email(), 'password': 'secret'},
states: {'admin': (f) => {'role': 'admin'}},
);
await userFactory.count(3).state('admin').create();
Constructors
-
ModelFactory(ModelDefinition<
T> definition, FactoryDefinition _define, {Map<String, FactoryState> states = const <String, FactoryState>{}, Faker? faker, DatabaseManager? db})
Properties
-
definition
→ ModelDefinition<
T> -
final
- faker → Faker
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
states
→ Map<
String, FactoryState> -
Named states usable via
state('admin').final
Methods
-
afterCreating(
FutureOr< void> callback(T model)) → ModelFactory<T> -
afterMaking(
FutureOr< void> callback(T model)) → ModelFactory<T> -
count(
int count) → ModelFactory< T> -
Number of models produced by
make()/create()plural variants. -
create(
[Map< String, Object?> overrides = const {}]) → Future<T> - Builds and saves one model.
-
createMany(
[Map< String, Object?> overrides = const {}, int? count]) → Future<ModelCollection< T> > -
Builds and saves
count(orcount()) models. -
make(
[Map< String, Object?> overrides = const {}]) → Future<T> - Builds one unsaved model.
-
makeMany(
[Map< String, Object?> overrides = const {}, int? count]) → Future<ModelCollection< T> > -
Builds
count(orcount()) unsaved models. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
raw(
[Map< String, Object?> overrides = const {}, int index = 0]) → Map<String, Object?> -
Raw attributes for the
index-th model. -
sequence(
List< Map< values) → ModelFactory<String, Object?> >T> -
Cycles through
valuesfor successive models. -
state(
Object state) → ModelFactory< T> - Applies a state: a named state, a map of overrides or a closure.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited