state<T> static method
Define a state for a factory.
States allow you to define variations of your factory.
Example:
NyFactory.state<User>('admin', (user, faker) {
return user.copyWith(role: 'admin');
});
final admin = NyFactory.make<User>(states: ['admin']);
Implementation
static void state<T>(
String name,
T Function(T instance, NyFaker faker) modifier,
) {
final key = '${T}_$name';
_stateDefinitions[key] = FactoryState<T>(modifier);
_states[T] ??= [];
if (!_states[T]!.contains(name)) {
_states[T]!.add(name);
}
}