This commit is contained in:
2025-03-23 16:12:37 +02:00
parent acf5ffb931
commit 87fd26a4ae

View File

@@ -82,28 +82,26 @@ class AstromicFormController extends FormController {
/// Prepare a hosted value.
void prepareValue<T>(String id, bool isRequired) {
return _hostedValues.addEntries(<MapEntry<String, (T?, bool)>>[MapEntry<String, (T?, bool)>(id, (null, isRequired))]);
if (!_hostedValues.keys.toList().contains(id)) {
return _hostedValues.addEntries(<MapEntry<String, (T?, bool)>>[MapEntry<String, (T?, bool)>(id, (null, isRequired))]);
}
}
/// Set the value of a hosted state variable using it's ID.
void setValue<T>(String id, T data, {bool isRequired = false}) {
if (!_hostedValues.keys.toList().contains(id)) {
prepareValue(id, isRequired);
}
prepareValue(id, isRequired);
_hostedValues[id] = (data, isRequired);
_hostedValueValidationStreamController.add((id, false));
}
/// Get the value of a hosted state variable using it's ID.
T? getValue<T>(String id) {
if (_hostedValues.keys.toList().contains(id)) {
if (_hostedValues[id]?.$1 is T?) {
return _hostedValues[id]?.$1;
} else {
throw FlutterError('Value found but is not of the type $T, it\'s of type ${_hostedValues[id]?.$1.runtimeType}');
}
prepareValue(id, false);
if (_hostedValues[id]?.$1 is T?) {
return _hostedValues[id]?.$1;
} else {
return null;
throw FlutterError('Value found but is not of the type $T, it\'s of type ${_hostedValues[id]?.$1.runtimeType}');
}
}