part of '../../settings.dart'; class SelectOption extends Option { SelectOption({ required super.storage, required super.key, required super.label, required super.defaultValue, required this.values, super.category, super.enabled, }) { stream = BehaviorSubject(); unawaited( values.first.then((final vs) async { final valueStr = storage.getString(key); T? initialValue; if (valueStr != null) { initialValue = _fromString(vs, valueStr); } stream.add(initialValue ?? await defaultValue.first); }), ); } T? _fromString(final Map vs, final String? valueStr) { final v = vs.keys.where((final e) => e.toString() == valueStr).toList(); if (v.length == 1) { return v[0]; } return null; } final BehaviorSubject> values; @override Future set(final T value) { stream.add(value); return storage.setString(key, value.toString()); } @override String? serialize() => value?.toString(); @override Future deserialize(final dynamic data) async => _fromString(await values.first, data as String?); }