[SYNC]
This commit is contained in:
@@ -96,15 +96,8 @@ class AstromicFormController extends FormController {
|
||||
|
||||
//S1 - Methods
|
||||
|
||||
/// 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))]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all the hosted values IDs.
|
||||
Map<String, (dynamic,bool)> get allValues => _hostedValues;
|
||||
Map<String, (dynamic, bool)> get allValues => _hostedValues;
|
||||
|
||||
/// Get the value of a hosted state variable using it's ID.
|
||||
T? getValue<T>(String id) {
|
||||
@@ -120,12 +113,17 @@ class AstromicFormController extends FormController {
|
||||
}
|
||||
|
||||
/// Set the value of a hosted state variable using it's ID.
|
||||
void setValue<T>(String id, T data, {bool isRequired = false}) {
|
||||
prepareValue(id, isRequired);
|
||||
void setValue<T>(String id, T? data, {bool isRequired = false}) {
|
||||
if (!_hostedValues.keys.toList().contains(id)) {
|
||||
return _hostedValues.addEntries(<MapEntry<String, (T?, bool)>>[MapEntry<String, (T?, bool)>(id, (null, isRequired))]);
|
||||
}
|
||||
//
|
||||
_hostedValues[id] = (data, _hostedValues[id]!.$2);
|
||||
else {
|
||||
bool isReq = _hostedValues[id]!.$2;
|
||||
_hostedValues[id] = (data, isReq);
|
||||
_hostedValueValidationStreamController.add((id, false));
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove the value of a hosted state variable using it's ID.
|
||||
void removeValue(String id) {
|
||||
|
||||
@@ -61,7 +61,7 @@ class _FormValueWrapperState<T> extends State<FormValueWrapper<T>> {
|
||||
//s1 --State
|
||||
//
|
||||
//s1 --Controllers & Listeners
|
||||
widget.controller.prepareValue<T>(widget.id, widget.isRequired);
|
||||
widget.controller.setValue<T>(widget.id, null, isRequired: widget.isRequired);
|
||||
//s1 --Controllers & Listeners
|
||||
//
|
||||
//s1 --Late & Async Initializers
|
||||
@@ -110,7 +110,7 @@ class _FormValueWrapperState<T> extends State<FormValueWrapper<T>> {
|
||||
builder: (BuildContext context, AsyncSnapshot<(String, bool)> validationSnapshot) {
|
||||
return widget.builder(widget.controller.getValue<T>(widget.id),
|
||||
validationSnapshot.hasData && validationSnapshot.data != null && validationSnapshot.data!.$1 == widget.id && validationSnapshot.data!.$2 ? true : false, (T newValue) {
|
||||
return widget.controller.setValue(widget.id, newValue, isRequired: widget.isRequired);
|
||||
return widget.controller.setValue(widget.id, newValue);
|
||||
}, () => widget.controller.removeValue(widget.id));
|
||||
});
|
||||
//!SECTION
|
||||
|
||||
Reference in New Issue
Block a user