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..6eab9c7aaf1 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,17 @@ 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 = false, 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 +32,27 @@ 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 = false, 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 = false}) { + if (forceLoad) { + assert(vs.isEmpty, 'Force loading should only be used when no initial valus are specified.'); + assert(stored is T?, 'Force loading is only supported on String values.'); + + return stored as T?; + } + + return _fromString(vs, stored); + } static T? _fromString(final Map vs, final String? valueStr) { if (valueStr == null) { diff --git a/packages/neon/neon/lib/src/utils/account_options.dart b/packages/neon/neon/lib/src/utils/account_options.dart index fc8c170fc1f..1b0dde44184 100644 --- a/packages/neon/neon/lib/src/utils/account_options.dart +++ b/packages/neon/neon/lib/src/utils/account_options.dart @@ -49,6 +49,7 @@ class AccountSpecificOptions { key: 'initial-app', label: (final context) => AppLocalizations.of(context).accountOptionsInitialApp, defaultValue: null, + forceLoadValue: true, values: {}, ); } diff --git a/packages/neon/neon/lib/src/utils/global_options.dart b/packages/neon/neon/lib/src/utils/global_options.dart index 0f056fbb601..da93c0a6e30 100644 --- a/packages/neon/neon/lib/src/utils/global_options.dart +++ b/packages/neon/neon/lib/src/utils/global_options.dart @@ -163,6 +163,7 @@ class GlobalOptions { key: 'push-notifications-distributor', label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsDistributor, defaultValue: null, + forceLoadValue: true, values: {}, enabled: pushNotificationsEnabled, ); @@ -210,6 +211,7 @@ class GlobalOptions { key: 'initial-account', label: (final context) => AppLocalizations.of(context).globalOptionsAccountsInitialAccount, defaultValue: null, + forceLoadValue: true, values: {}, );