This commit is contained in:
2025-04-15 15:41:55 +02:00
parent 670878c2e7
commit 9643ba5d1a
2 changed files with 12 additions and 14 deletions

View File

@@ -96,15 +96,8 @@ class AstromicFormController extends FormController {
//S1 - Methods //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. /// 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. /// Get the value of a hosted state variable using it's ID.
T? getValue<T>(String id) { T? getValue<T>(String id) {
@@ -120,11 +113,16 @@ class AstromicFormController extends FormController {
} }
/// 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}) {
prepareValue(id, isRequired); 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 {
_hostedValueValidationStreamController.add((id, false)); 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. /// Remove the value of a hosted state variable using it's ID.

View File

@@ -61,7 +61,7 @@ class _FormValueWrapperState<T> extends State<FormValueWrapper<T>> {
//s1 --State //s1 --State
// //
//s1 --Controllers & Listeners //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 --Controllers & Listeners
// //
//s1 --Late & Async Initializers //s1 --Late & Async Initializers
@@ -110,7 +110,7 @@ class _FormValueWrapperState<T> extends State<FormValueWrapper<T>> {
builder: (BuildContext context, AsyncSnapshot<(String, bool)> validationSnapshot) { builder: (BuildContext context, AsyncSnapshot<(String, bool)> validationSnapshot) {
return widget.builder(widget.controller.getValue<T>(widget.id), 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) { 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)); }, () => widget.controller.removeValue(widget.id));
}); });
//!SECTION //!SECTION