[0.1.2]
This commit is contained in:
@@ -82,29 +82,27 @@ class AstromicFormController extends FormController {
|
||||
|
||||
/// Prepare a hosted value.
|
||||
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))]);
|
||||
}
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
_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)) {
|
||||
prepareValue(id, false);
|
||||
|
||||
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}');
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user