BaseHako constructor
- void registrar(
- RegisterCallback register
Creates a new instance and registers initial state values.
This constructor takes a registrar function that is immediately called with a RegisterCallback to allow subclasses to declare and initialize all their state values upfront. The registrar pattern ensures that all state is defined during construction, enabling type-safe access throughout the container's lifecycle.
The provided registrar function should call the register callback
for each state value that needs to be managed by this Hako instance.
Each state value must be registered with its exact type and an optional
name for disambiguation when multiple values of the same type are needed.
Example usage in a subclass:
class CounterHako extends BaseHako {
CounterHako() : super((register) {
register<int>(0);
register<String>('idle');
register<bool>(false);
register<String>('primary', name: 'theme');
});
}
registrar A function that receives a RegisterCallback and should
use it to register all initial state values for this Hako instance.
The function is called immediately during construction to populate
the internal state map.
Implementation
BaseHako(void Function(RegisterCallback register) registrar) {
registrar(_registerInitialState);
}