|
|
@ -71,6 +71,7 @@ sealed class Option<T> extends ChangeNotifier implements ValueListenable<T>, Dis |
|
|
|
/// listeners. |
|
|
|
/// listeners. |
|
|
|
@override |
|
|
|
@override |
|
|
|
T get value => _value; |
|
|
|
T get value => _value; |
|
|
|
|
|
|
|
|
|
|
|
@mustCallSuper |
|
|
|
@mustCallSuper |
|
|
|
set value(final T newValue) { |
|
|
|
set value(final T newValue) { |
|
|
|
if (_value == newValue) { |
|
|
|
if (_value == newValue) { |
|
|
@ -88,6 +89,7 @@ sealed class Option<T> extends ChangeNotifier implements ValueListenable<T>, Dis |
|
|
|
/// value as evaluated by the equality operator ==, this class notifies its |
|
|
|
/// value as evaluated by the equality operator ==, this class notifies its |
|
|
|
/// listeners. |
|
|
|
/// listeners. |
|
|
|
bool get enabled => _enabled; |
|
|
|
bool get enabled => _enabled; |
|
|
|
|
|
|
|
|
|
|
|
@mustCallSuper |
|
|
|
@mustCallSuper |
|
|
|
set enabled(final bool newValue) { |
|
|
|
set enabled(final bool newValue) { |
|
|
|
if (_enabled == newValue) { |
|
|
|
if (_enabled == newValue) { |
|
|
@ -108,7 +110,9 @@ sealed class Option<T> extends ChangeNotifier implements ValueListenable<T>, Dis |
|
|
|
final value = deserialize(data); |
|
|
|
final value = deserialize(data); |
|
|
|
|
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
this.value = value; |
|
|
|
// Do not trigger the validation to avoid resetting when the values haven't been loaded yet. |
|
|
|
|
|
|
|
_value = value; |
|
|
|
|
|
|
|
notifyListeners(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -203,10 +207,14 @@ class SelectOption<T> extends Option<T> { |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
set value(final T value) { |
|
|
|
set value(final T value) { |
|
|
|
super.value = value; |
|
|
|
if (_values.keys.contains(value)) { |
|
|
|
|
|
|
|
super.value = value; |
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
unawaited(storage.setString(key.value, serialize()!)); |
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
unawaited(storage.setString(key.value, serialize()!)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
debugPrint('"$value" is not in "${_values.keys.join('", "')}", ignoring'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -224,6 +232,10 @@ class SelectOption<T> extends Option<T> { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
_values = newValues; |
|
|
|
_values = newValues; |
|
|
|
|
|
|
|
if (!_values.keys.contains(_value)) { |
|
|
|
|
|
|
|
debugPrint('"$value" is not in "${_values.keys.join('", "')}", resetting "${key.value}"'); |
|
|
|
|
|
|
|
reset(); |
|
|
|
|
|
|
|
} |
|
|
|
notifyListeners(); |
|
|
|
notifyListeners(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|