init method
Initialize the global state with SharedPreferences and state descriptors
descriptors - List of state descriptors to initialize
prefs - SharedPreferences instance
Implementation
Future<void> init(List<dynamic> values) async {
if (_isInitialized) {
dispose();
}
final descriptors =
values.map((e) => StateDescriptorFactory().fromJson(e)).toList();
for (final descriptor in descriptors) {
if (_values.containsKey(descriptor.key)) {
throw Exception('Duplicate state key: ${descriptor.key}');
}
// Create either PersistedReactiveValue or ReactiveValue based on shouldPersist
final value = DefaultReactiveValueFactory().create(
descriptor,
PreferencesStore.instance.prefs,
);
_values[descriptor.key] = value;
}
_isInitialized = true;
}