[0.1.2]
This commit is contained in:
@@ -36,7 +36,7 @@ class AstromicFormController extends FormController {
|
||||
this.errorStream,
|
||||
}) : super(initialValues) {
|
||||
// Add states and messages based on initial controller.
|
||||
_addInitialControllers(initialValues ?? <String, (String, bool)>{});
|
||||
_addInitialControllers(initialValues);
|
||||
}
|
||||
|
||||
/// 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.
|
||||
void setState(String fieldId, AstromicFieldState state, {String? message}) {
|
||||
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;
|
||||
fieldMessages[fieldId] = message;
|
||||
@@ -99,7 +99,7 @@ class AstromicFormController extends FormController {
|
||||
TextEditingController controller(String id, {String? initialText, bool isObscure = false}) {
|
||||
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)]);
|
||||
fieldMessages.addEntries(<MapEntry<String, String?>>[MapEntry<String, String?>(id, null)]);
|
||||
}
|
||||
@@ -112,18 +112,20 @@ class AstromicFormController extends FormController {
|
||||
}
|
||||
|
||||
//SECTION - Helper Methods
|
||||
_addInitialControllers(Map<String, (String, bool)> initialValues) {
|
||||
// Add in the initial field states...
|
||||
fieldStates.addEntries(initialValues.entries.toList().map((MapEntry<String, (String, bool)> e) => MapEntry<String, AstromicFieldState>(
|
||||
e.key, // controller ID
|
||||
AstromicFieldState.idle, // Initial state of any new controller is Idle
|
||||
)));
|
||||
void _addInitialControllers(Map<String, (String, bool)>? initialValues) {
|
||||
if (initialValues != null) {
|
||||
// Add in the initial field states...
|
||||
fieldStates.addEntries(initialValues.entries.map((MapEntry<String, (String, bool)> e) => MapEntry<String, AstromicFieldState>(
|
||||
e.key, // controller ID
|
||||
AstromicFieldState.idle, // Initial state of any new controller is Idle
|
||||
)));
|
||||
|
||||
// Add in the initial field messages...
|
||||
fieldMessages.addEntries(initialValues.entries.toList().map((MapEntry<String, (String, bool)> e) => MapEntry<String, String?>(
|
||||
e.key, // Controller ID
|
||||
null, // The initial message it has which is Null
|
||||
)));
|
||||
// Add in the initial field messages...
|
||||
fieldMessages.addEntries(initialValues.entries.toList().map((MapEntry<String, (String, bool)> e) => MapEntry<String, String?>(
|
||||
e.key, // Controller ID
|
||||
null, // The initial message it has which is Null
|
||||
)));
|
||||
}
|
||||
}
|
||||
//!SECTION
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user