This commit is contained in:
2025-04-27 14:08:21 +03:00
3 changed files with 17 additions and 17 deletions

View File

@@ -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,11 +113,16 @@ 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);
_hostedValueValidationStreamController.add((id, false));
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.

View File

@@ -23,7 +23,7 @@ class FormValueWrapper<T extends Object?> extends StatefulWidget {
final AstromicFormController controller;
final String id;
final bool isRequired;
final Widget Function(T? value, bool isErroredForValidation, void Function(T value) valueSetter, VoidCallback valueClear) builder;
final Widget Function(T? value, bool isErroredForValidation, void Function(T? value) valueSetter, VoidCallback valueClear) builder;
//!SECTION
//
const FormValueWrapper({
@@ -61,7 +61,9 @@ class _FormValueWrapperState<T> extends State<FormValueWrapper<T>> {
//s1 --State
//
//s1 --Controllers & Listeners
widget.controller.prepareValue<T>(widget.id, widget.isRequired);
if (!widget.controller.allValues.keys.contains(widget.id)) {
widget.controller.setValue<T>(widget.id, null, isRequired: widget.isRequired);
}
//s1 --Controllers & Listeners
//
//s1 --Late & Async Initializers
@@ -109,8 +111,8 @@ class _FormValueWrapperState<T> extends State<FormValueWrapper<T>> {
stream: widget.controller.hostedValueValidationStream,
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);
validationSnapshot.hasData && validationSnapshot.data != null && validationSnapshot.data!.$1 == widget.id && validationSnapshot.data!.$2 ? true : false, (T? newValue) {
return widget.controller.setValue(widget.id, newValue);
}, () => widget.controller.removeValue(widget.id));
});
//!SECTION

View File

@@ -128,7 +128,7 @@ class _AstromicFuturePresenterState<T> extends State<AstromicFuturePresenter<T>>
//S1 -- Method to reinitialize or update `_future` with a new instance
void _initializeFuture() {
_future = widget.controller.getFuture<T?>(widget.id)?.then((result) => result);
_future = widget.controller.getFuture(widget.id)?.then((dynamic result) => result as T?);
}
//!SECTION