[0.1.2]
This commit is contained in:
@@ -82,29 +82,27 @@ class AstromicFormController extends FormController {
|
|||||||
|
|
||||||
/// Prepare a hosted value.
|
/// Prepare a hosted value.
|
||||||
void prepareValue<T>(String id, bool isRequired) {
|
void prepareValue<T>(String id, bool isRequired) {
|
||||||
|
if (!_hostedValues.keys.toList().contains(id)) {
|
||||||
return _hostedValues.addEntries(<MapEntry<String, (T?, bool)>>[MapEntry<String, (T?, bool)>(id, (null, isRequired))]);
|
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.
|
/// Set the value of a hosted state variable using it's ID.
|
||||||
void setValue<T>(String id, T data, {bool isRequired = false}) {
|
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);
|
_hostedValues[id] = (data, isRequired);
|
||||||
_hostedValueValidationStreamController.add((id, false));
|
_hostedValueValidationStreamController.add((id, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the value of a hosted state variable using it's ID.
|
/// Get the value of a hosted state variable using it's ID.
|
||||||
T? getValue<T>(String id) {
|
T? getValue<T>(String id) {
|
||||||
if (_hostedValues.keys.toList().contains(id)) {
|
prepareValue(id, false);
|
||||||
|
|
||||||
if (_hostedValues[id]?.$1 is T?) {
|
if (_hostedValues[id]?.$1 is T?) {
|
||||||
return _hostedValues[id]?.$1;
|
return _hostedValues[id]?.$1;
|
||||||
} else {
|
} else {
|
||||||
throw FlutterError('Value found but is not of the type $T, it\'s of type ${_hostedValues[id]?.$1.runtimeType}');
|
throw FlutterError('Value found but is not of the type $T, it\'s of type ${_hostedValues[id]?.$1.runtimeType}');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Reference in New Issue
Block a user