handleDynamicFormSubmit method
void
handleDynamicFormSubmit()
Implementation
void handleDynamicFormSubmit() {
validateAllFields();
// Check for any errors first
if (errors.values.any((error) => error != null)) {
nestedObject = null;
return;
}
// Check if form is optional and no fields are touched
if (formValidation == "optional" && !touched.values.any((touch) => touch)) {
nestedObject = null;
return;
}
// Debug: Print current values before constructing nested object
debugPrint('=== DEBUG: Current values before constructNestedObject ===');
values.forEach((key, value) {
if (key.contains('floor_details')) {
debugPrint('$key: $value');
}
});
debugPrint('=== END DEBUG ===');
// Construct nested object
final constructedObject = constructNestedObject(values);
// Debug: Print constructed object
debugPrint('=== DEBUG: Constructed nested object ===');
if (constructedObject.containsKey('property_details')) {
final propertyDetails = constructedObject['property_details'];
if (propertyDetails is List && propertyDetails.isNotEmpty) {
final firstProperty = propertyDetails[0];
if (firstProperty is Map && firstProperty.containsKey('data')) {
final data = firstProperty['data'];
if (data is Map && data.containsKey('floor_details')) {
final floorDetails = data['floor_details'];
debugPrint('floor_details: $floorDetails');
}
}
}
}
debugPrint('=== END DEBUG ===');
// Only set nestedObject if the constructed object is not empty
if (constructedObject.isNotEmpty) {
nestedObject = constructedObject;
errors.clear();
touched.clear();
submitted = false;
}
notifyListeners();
}