[SYNC]
This commit is contained in:
@@ -121,6 +121,14 @@ class AstromicFormController extends FormController {
|
||||
_hostedValueValidationStreamController.add((id, false));
|
||||
}
|
||||
|
||||
/// Remove the value of a hosted state variable using it's ID.
|
||||
void removeValue(String id) {
|
||||
if (!_hostedValues.keys.toList().contains(id)) {
|
||||
throw Exception('Value of id `$id` not found to be removed.');
|
||||
}
|
||||
_hostedValues.remove(id);
|
||||
}
|
||||
|
||||
/// Validate hosted values.
|
||||
bool validateValues(List<String> valueIDs) {
|
||||
for (String hostedValueID in valueIDs) {
|
||||
@@ -331,35 +339,34 @@ class AstromicFormController extends FormController {
|
||||
return fullPath != null && fullPath.length > 1 && fullPath.indexOf(formGroupID) != 0;
|
||||
}
|
||||
|
||||
String addInstanceToFormGroup(String formGroupID, {Map<String, int>? parentsPrefixes}) {
|
||||
String addInstanceToFormGroup(String formGroupID, {Map<String, int>? parents}) {
|
||||
// Get the group structure with the same ID
|
||||
FormGroupStructure? structure = getGroupStructure(formGroupID);
|
||||
assert(structure != null, 'The Group $formGroupID doesn\'t seem to be found, are you sure you initialized it?');
|
||||
|
||||
// Get current instances of this group
|
||||
int currentGroupInstances = getInstanceCount(formGroupID);
|
||||
int newGroupIndex = currentGroupInstances + 1;
|
||||
|
||||
if (structure!.subGroups != null && structure.subGroups!.isNotEmpty) {
|
||||
for ((int gI, FormGroupStructure gS) f in structure.subGroups!) {
|
||||
addInstanceToFormGroup(formGroupID, parentsPrefixes: {
|
||||
...?parentsPrefixes,
|
||||
...{formGroupID: newGroupIndex},
|
||||
});
|
||||
}
|
||||
// Get the prefix for subgroups if exists
|
||||
String? prefix;
|
||||
if (isASubGroup(formGroupID) && parents != null) {
|
||||
prefix = parents.entries.map((MapEntry<String, int> parentEntry) => standeredGroupFormat(parentEntry.key, parentEntry.value.toString(), null)).join('-');
|
||||
}
|
||||
|
||||
String prefixedGroup = parentsPrefixes?.entries.map((MapEntry<String, int> p) => standeredGroupFormat(p.key, p.value.toString(), null)).toList().join('-') ?? '';
|
||||
// Get current instances of this group and the new index.
|
||||
int currentGroupInstances = getInstanceCount(formGroupID);
|
||||
int newGroupIndex = currentGroupInstances;
|
||||
|
||||
// Add the controllers and values.
|
||||
for (String fieldID in structure.fields.nonNulls) {
|
||||
controller(prefixedGroup + standeredGroupFormat(formGroupID, newGroupIndex.toString(), fieldID));
|
||||
for (String fieldID in structure!.fields.nonNulls) {
|
||||
String p = (prefix != null ? '$prefix-' : '') + standeredGroupFormat(formGroupID, newGroupIndex.toString(), fieldID);
|
||||
controller(p);
|
||||
}
|
||||
if (structure.values != null && structure.values!.isNotEmpty) {
|
||||
for (String valueID in structure.values!.nonNulls) {
|
||||
controller(prefixedGroup + standeredGroupFormat(formGroupID, newGroupIndex.toString(), valueID));
|
||||
String p = (prefix != null ? '$prefix-' : '') + standeredGroupFormat(formGroupID, newGroupIndex.toString(), valueID);
|
||||
controller(p);
|
||||
}
|
||||
}
|
||||
return prefixedGroup + standeredGroupFormat(formGroupID, newGroupIndex.toString(), '');
|
||||
String p = (prefix != null ? '$prefix-' : '') + standeredGroupFormat(formGroupID, newGroupIndex.toString(), '');
|
||||
return p;
|
||||
}
|
||||
|
||||
// void removeInstanceFromFormGroup(String formGroupID, int indexToRemove, {bool isSubGroup = false}) {
|
||||
|
||||
Reference in New Issue
Block a user