body method

Map<String, dynamic> body()

Generates a map from the form state, applying any transformations specified by the fieldTransformers method.

This method iterates over all fields in the form state, applies any registered transformers, and returns a map suitable for use as a request body.

Returns: A Map<String, dynamic> containing the transformed form data.

Implementation

Map<String, dynamic> body() {
  final _registry = TransformersRegistry();
  fieldTransformers(_registry);

  final map = <String, dynamic>{};

  // Iterate through each field in the fields map
  state.fields.forEach((fieldName, fieldState) {
    final fieldValue = fieldState.value;
    final newValue = _registry.transform(fieldValue);
    if (newValue != null) {
      map[fieldName] = newValue;
    } else {
      map[fieldName] = fieldValue;
    }
  });

  return map;
}