[SYNC]
This commit is contained in:
@@ -70,9 +70,15 @@ class AstromicFormController extends FormController {
|
||||
|
||||
// Add the controllers and values.
|
||||
for (int i = 0; i < initialCount; i++) {
|
||||
for (MapEntry<String, bool> fieldEntry in groupStructure.fields.entries) {
|
||||
String fieldID = '${groupStructure.id}-#$i-${fieldEntry.key}';
|
||||
controller(fieldID);
|
||||
for (String fieldID in groupStructure.fields) {
|
||||
String finalFieldID = '${groupStructure.id}-#$i-$fieldID';
|
||||
controller(finalFieldID);
|
||||
}
|
||||
if (groupStructure.values != null && groupStructure.values!.isNotEmpty) {
|
||||
for (String valueID in groupStructure.values!.map(((String, Type) a) => a.$1).toList()) {
|
||||
String finalFieldID = '${groupStructure.id}-#$i-$valueID';
|
||||
controller(finalFieldID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,15 +126,15 @@ class AstromicFormController extends FormController {
|
||||
|
||||
// Get the current fields with this ID
|
||||
Map<String, String> firstSetOfFieldsWithID = Map<String, String>.fromEntries(
|
||||
controllers.entries.where((MapEntry<String, String> c) => RegExp(formGroupID + r'-#[\d+]-' + groupStructure!.fields.entries.first.key).hasMatch(c.key)).nonNulls.toList(),
|
||||
controllers.entries.where((MapEntry<String, String> c) => RegExp(formGroupID + r'-#[\d+]-' + groupStructure!.fields.first).hasMatch(c.key)).nonNulls.toList(),
|
||||
);
|
||||
|
||||
print('First set of fields: $firstSetOfFieldsWithID');
|
||||
// get the fields IDs
|
||||
List<String> fieldsIDs = groupStructure!.fields.entries.where((MapEntry<String, bool> e) => !e.value).nonNulls.map((MapEntry<String, bool> ee) => ee.key).toList();
|
||||
List<String> fieldsIDs = groupStructure!.fields.nonNulls.toList();
|
||||
print('fieldIDs: $fieldsIDs');
|
||||
// get the values IDs
|
||||
List<String> valuesIDs = groupStructure.fields.entries.where((MapEntry<String, bool> e) => e.value).nonNulls.map((MapEntry<String, bool> ee) => ee.key).toList();
|
||||
List<(String, Type)> valuesIDs = groupStructure.values?.nonNulls.toList() ?? <(String, Type)>[];
|
||||
print('valueIDs: $valuesIDs');
|
||||
|
||||
// get the subGroups
|
||||
@@ -143,7 +149,7 @@ class AstromicFormController extends FormController {
|
||||
instances.add(
|
||||
FormGroupInstance(
|
||||
fields: Map<String, String>.fromEntries(fieldsIDs.map((String id) => MapEntry<String, String>('$formGroupID-#$i-$id', value('$formGroupID-#$i-$id'))).toList()),
|
||||
values: Map<String, dynamic>.fromEntries(valuesIDs.map((String id) => MapEntry<String, String>('$formGroupID-#$i-$id', getValue('$formGroupID-#$i-$id'))).toList()),
|
||||
values: Map<String, dynamic>.fromEntries(valuesIDs.map(((String, Type) a) => MapEntry<String, String>('$formGroupID-#$i-${a.$1}', getValue<dynamic>('$formGroupID-#$i-${a.$1}'))).toList()),
|
||||
subGroups: subValues,
|
||||
),
|
||||
);
|
||||
@@ -194,7 +200,6 @@ class AstromicFormController extends FormController {
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// Map<String,Map<String,dynamic>> getFormGroup(String groupID){}
|
||||
|
||||
/// Get the field state and message of a specific field using it's ID.
|
||||
|
||||
@@ -4,22 +4,26 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
class FormGroupStructure {
|
||||
final String id;
|
||||
final Map<String, bool> fields;
|
||||
final List<String> fields;
|
||||
final List<(String, Type)>? values;
|
||||
final List<FormGroupStructure>? subGroups;
|
||||
FormGroupStructure({
|
||||
required this.id,
|
||||
required this.fields,
|
||||
this.values,
|
||||
this.subGroups,
|
||||
});
|
||||
|
||||
FormGroupStructure copyWith({
|
||||
String? id,
|
||||
Map<String, bool>? fields,
|
||||
List<String>? fields,
|
||||
List<(String, Type)>? values,
|
||||
List<FormGroupStructure>? subGroups,
|
||||
}) {
|
||||
return FormGroupStructure(
|
||||
id: id ?? this.id,
|
||||
fields: fields ?? this.fields,
|
||||
values: values ?? this.values,
|
||||
subGroups: subGroups ?? this.subGroups,
|
||||
);
|
||||
}
|
||||
@@ -28,6 +32,7 @@ class FormGroupStructure {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'fields': fields,
|
||||
'values': values?.map(((String, Type) x) => <String, Object>{'id': x.$1, 'type': x.$2}).toList(),
|
||||
'subGroups': subGroups?.map((FormGroupStructure x) => x.toMap()).toList(),
|
||||
};
|
||||
}
|
||||
@@ -35,14 +40,9 @@ class FormGroupStructure {
|
||||
factory FormGroupStructure.fromMap(Map<String, dynamic> map) {
|
||||
return FormGroupStructure(
|
||||
id: map['id'] as String,
|
||||
fields: Map<String, bool>.from(map['fields'] as Map<String, bool>),
|
||||
subGroups: map['subGroups'] != null
|
||||
? List<FormGroupStructure>.from(
|
||||
(map['subGroups'] as List<int>).map<FormGroupStructure?>(
|
||||
(int x) => FormGroupStructure.fromMap(x as Map<String, dynamic>),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
fields: List<String>.from(map['fields'] as List<String>),
|
||||
values: map['values'] != null ? (map['values'] as Map<String,dynamic>).entries.map((MapEntry<String, dynamic> entry) => (entry.key.toString(),entry.value.runtimeType)).toList() : null,
|
||||
subGroups: map['subGroups'] != null ? (map['subGroups'] as List<Map<String, dynamic>>).map((Map<String, dynamic> f) => FormGroupStructure.fromMap(f)).toList() : null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,18 +52,25 @@ class FormGroupStructure {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'FormGroup(id: $id, fields: $fields, subGroups: $subGroups)';
|
||||
return 'FormGroupStructure(id: $id, fields: $fields, values: $values, subGroups: $subGroups)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant FormGroupStructure other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.id == id && mapEquals(other.fields, fields) && listEquals(other.subGroups, subGroups);
|
||||
return
|
||||
other.id == id &&
|
||||
listEquals(other.fields, fields) &&
|
||||
listEquals(other.values, values) &&
|
||||
listEquals(other.subGroups, subGroups);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return id.hashCode ^ fields.hashCode ^ subGroups.hashCode;
|
||||
return id.hashCode ^
|
||||
fields.hashCode ^
|
||||
values.hashCode ^
|
||||
subGroups.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user