buildUpdatePayload function

Map<String, dynamic> buildUpdatePayload(
  1. String name,
  2. String value,
  3. bool isMultiValued, {
  4. String? type,
})

Builds the nested attributes payload segment for a single dot-path field save.

Implementation

Map<String, dynamic> buildUpdatePayload(
  String name,
  String value,
  bool isMultiValued, {
  String? type,
}) {
  final Object resolved;
  if (isMultiValued) {
    resolved = value
        .split(',')
        .map((part) => part.trim())
        .where((part) => part.isNotEmpty)
        .toList();
  } else if (type == 'BOOLEAN') {
    // Editors hold every value as text; the schema types this one as a JSON
    // boolean, so send a real bool rather than the string 'true'/'false'.
    resolved = value.toLowerCase() == 'true';
  } else {
    resolved = value;
  }
  return _buildNestedMap(name.split('.'), resolved);
}