[SYNC]
This commit is contained in:
@@ -17,6 +17,8 @@ import 'models/form_group_structure.model.dart';
|
|||||||
import 'models/form_group_value.model.dart';
|
import 'models/form_group_value.model.dart';
|
||||||
//s1 Exports
|
//s1 Exports
|
||||||
|
|
||||||
|
part './helpers/controller_states.helper.dart';
|
||||||
|
|
||||||
/// A specialized form controller to handle form states,
|
/// A specialized form controller to handle form states,
|
||||||
class AstromicFormController extends FormController {
|
class AstromicFormController extends FormController {
|
||||||
AstromicFormController({
|
AstromicFormController({
|
||||||
@@ -49,9 +51,13 @@ class AstromicFormController extends FormController {
|
|||||||
@override
|
@override
|
||||||
void removeController(String id) {
|
void removeController(String id) {
|
||||||
super.removeController(id);
|
super.removeController(id);
|
||||||
|
|
||||||
|
// Remove the field state
|
||||||
if (fieldStates.containsKey(id)) {
|
if (fieldStates.containsKey(id)) {
|
||||||
fieldStates.remove(id);
|
fieldStates.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove the field message
|
||||||
if (fieldMessages.containsKey(id)) {
|
if (fieldMessages.containsKey(id)) {
|
||||||
fieldMessages.remove(id);
|
fieldMessages.remove(id);
|
||||||
}
|
}
|
||||||
@@ -68,24 +74,7 @@ class AstromicFormController extends FormController {
|
|||||||
final Stream<List<(String internalCode, String? message)>>? errorStream;
|
final Stream<List<(String internalCode, String? message)>>? errorStream;
|
||||||
//S1 - Methods
|
//S1 - Methods
|
||||||
|
|
||||||
/// Does the controller has a field with this ID.
|
|
||||||
bool hasKey(String id) => controllers.containsKey(id);
|
|
||||||
|
|
||||||
/// Get the field state and message of a specific field using it's ID.
|
|
||||||
(AstromicFieldState, String? message)? getState(String fieldId) => (fieldStates.containsKey(fieldId)) ? (fieldStates[fieldId]!, fieldMessages[fieldId]) : null;
|
|
||||||
|
|
||||||
/// Set the field state and message of a specific field using it's ID.
|
|
||||||
void setState(String fieldId, AstromicFieldState state, {String? message}) {
|
|
||||||
if (!fieldStates.containsKey(fieldId)) {
|
|
||||||
throw Exception('The state of the field ID $fieldId does not exist.');
|
|
||||||
}
|
|
||||||
fieldStates[fieldId] = state;
|
|
||||||
fieldMessages[fieldId] = message;
|
|
||||||
_stateStreamController.add((fieldId, state));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reset the state of a specific field using it's ID.
|
|
||||||
void resetState(String fieldId) => setState(fieldId, AstromicFieldState.idle);
|
|
||||||
//!SECTION
|
//!SECTION
|
||||||
|
|
||||||
//SECTION - Hosted Values
|
//SECTION - Hosted Values
|
||||||
|
|||||||
16
lib/src/form/src/helpers/controller_states.helper.dart
Normal file
16
lib/src/form/src/helpers/controller_states.helper.dart
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
part of '../controller.dart';
|
||||||
|
/// Get the field state and message of a specific field using it's ID.
|
||||||
|
(AstromicFieldState, String? message)? getState(String fieldId) => (fieldStates.containsKey(fieldId)) ? (fieldStates[fieldId]!, fieldMessages[fieldId]) : null;
|
||||||
|
|
||||||
|
/// Set the field state and message of a specific field using it's ID.
|
||||||
|
void setState(String fieldId, AstromicFieldState state, {String? message}) {
|
||||||
|
if (!fieldStates.containsKey(fieldId)) {
|
||||||
|
throw Exception('The state of the field ID $fieldId does not exist.');
|
||||||
|
}
|
||||||
|
fieldStates[fieldId] = state;
|
||||||
|
fieldMessages[fieldId] = message;
|
||||||
|
_stateStreamController.add((fieldId, state));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reset the state of a specific field using it's ID.
|
||||||
|
void resetState(String fieldId) => setState(fieldId, AstromicFieldState.idle);
|
||||||
Reference in New Issue
Block a user