register method
Registers a state handler with the given key.
key: Unique string identifier for this state contributorexporter: Function that exports state asMap<String, dynamic>importer: Function that imports state fromMap<String, dynamic>
Throws StateError if the key is already registered.
Thread-safe: This operation is synchronized.
Implementation
void register(
String key,
Map<String, dynamic> Function() exporter,
void Function(Map<String, dynamic>) importer,
) {
if (key.isEmpty) {
throw ArgumentError.value(key, 'key', 'Key cannot be empty');
}
synchronized(() {
if (_handlers.containsKey(key)) {
throw StateError(
'State handler with key "$key" is already registered. '
'Keys must be unique.',
);
}
_handlers[key] = _StateHandler(exporter: exporter, importer: importer);
});
}