[0.1.2]
This commit is contained in:
@@ -36,7 +36,7 @@ class AstromicFormController extends FormController {
|
|||||||
this.errorStream,
|
this.errorStream,
|
||||||
}) : super(initialValues) {
|
}) : super(initialValues) {
|
||||||
// Add states and messages based on initial controller.
|
// Add states and messages based on initial controller.
|
||||||
_addInitialControllers(initialValues ?? <String, (String, bool)>{});
|
_addInitialControllers(initialValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Does the controller has a field with this ID.
|
/// Does the controller has a field with this ID.
|
||||||
@@ -48,7 +48,7 @@ class AstromicFormController extends FormController {
|
|||||||
/// Set the field state and message of a specific field using it's ID.
|
/// Set the field state and message of a specific field using it's ID.
|
||||||
void setState(String fieldId, AstromicFieldState state, {String? message}) {
|
void setState(String fieldId, AstromicFieldState state, {String? message}) {
|
||||||
if (!fieldStates.containsKey(fieldId)) {
|
if (!fieldStates.containsKey(fieldId)) {
|
||||||
throw Exception('Field ID $fieldId does not exist.');
|
throw Exception('The state of the field ID $fieldId does not exist.');
|
||||||
}
|
}
|
||||||
fieldStates[fieldId] = state;
|
fieldStates[fieldId] = state;
|
||||||
fieldMessages[fieldId] = message;
|
fieldMessages[fieldId] = message;
|
||||||
@@ -99,7 +99,7 @@ class AstromicFormController extends FormController {
|
|||||||
TextEditingController controller(String id, {String? initialText, bool isObscure = false}) {
|
TextEditingController controller(String id, {String? initialText, bool isObscure = false}) {
|
||||||
TextEditingController ret = super.controller(id, initialText: initialText, isObscure: isObscure);
|
TextEditingController ret = super.controller(id, initialText: initialText, isObscure: isObscure);
|
||||||
//
|
//
|
||||||
if (!hasKey(id)) {
|
if (getState(id) == null) {
|
||||||
fieldStates.addEntries(<MapEntry<String, AstromicFieldState>>[MapEntry<String, AstromicFieldState>(id, AstromicFieldState.idle)]);
|
fieldStates.addEntries(<MapEntry<String, AstromicFieldState>>[MapEntry<String, AstromicFieldState>(id, AstromicFieldState.idle)]);
|
||||||
fieldMessages.addEntries(<MapEntry<String, String?>>[MapEntry<String, String?>(id, null)]);
|
fieldMessages.addEntries(<MapEntry<String, String?>>[MapEntry<String, String?>(id, null)]);
|
||||||
}
|
}
|
||||||
@@ -112,9 +112,10 @@ class AstromicFormController extends FormController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//SECTION - Helper Methods
|
//SECTION - Helper Methods
|
||||||
_addInitialControllers(Map<String, (String, bool)> initialValues) {
|
void _addInitialControllers(Map<String, (String, bool)>? initialValues) {
|
||||||
|
if (initialValues != null) {
|
||||||
// Add in the initial field states...
|
// Add in the initial field states...
|
||||||
fieldStates.addEntries(initialValues.entries.toList().map((MapEntry<String, (String, bool)> e) => MapEntry<String, AstromicFieldState>(
|
fieldStates.addEntries(initialValues.entries.map((MapEntry<String, (String, bool)> e) => MapEntry<String, AstromicFieldState>(
|
||||||
e.key, // controller ID
|
e.key, // controller ID
|
||||||
AstromicFieldState.idle, // Initial state of any new controller is Idle
|
AstromicFieldState.idle, // Initial state of any new controller is Idle
|
||||||
)));
|
)));
|
||||||
@@ -125,5 +126,6 @@ class AstromicFormController extends FormController {
|
|||||||
null, // The initial message it has which is Null
|
null, // The initial message it has which is Null
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//!SECTION
|
//!SECTION
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user