diff --git a/packages/neon/neon/lib/src/settings/models/select_option.dart b/packages/neon/neon/lib/src/settings/models/select_option.dart index 5d3fc7dae1b..e1d7e1108eb 100644 --- a/packages/neon/neon/lib/src/settings/models/select_option.dart +++ b/packages/neon/neon/lib/src/settings/models/select_option.dart @@ -12,10 +12,16 @@ class SelectOption extends Option { required super.label, required super.defaultValue, required final Map values, + + /// Force loading the stored value. + /// + /// This is needed when [values] is empty but the stored value should still be loaded. + /// This only works when [T] is of type String?. + final bool forceLoadValue = true, super.category, super.enabled, }) : _values = values, - super(initialValue: _fromString(values, storage.getString(key))); + super(initialValue: loadValue(values, storage.getString(key), forceLoad: forceLoadValue)); /// Creates a SelectOption depending on the State of another [Option]. SelectOption.depend({ @@ -25,9 +31,23 @@ class SelectOption extends Option { required super.defaultValue, required final Map values, required super.enabled, + + /// Force loading the stored value. + /// + /// This is needed when [values] is empty but the stored value should still be loaded. + /// This only works when [T] is of type String?. + final bool forceLoadValue = true, super.category, }) : _values = values, - super.depend(initialValue: _fromString(values, storage.getString(key))); + super.depend(initialValue: loadValue(values, storage.getString(key), forceLoad: forceLoadValue)); + + static T? loadValue(final Map vs, final String? stored, {final bool forceLoad = true}) { + if (forceLoad && vs.isEmpty && stored is T) { + return stored as T; + } + + return _fromString(vs, stored); + } static T? _fromString(final Map vs, final String? valueStr) { if (valueStr == null) {