readXraySchemaField function

Object? readXraySchemaField(
  1. Map<String, dynamic> object,
  2. String field
)

Read one inspected schema field without changing the imported document. Returns null for an absent or explicitly null field in object. Throws ArgumentError if several keys match the same schema field. Do not use this lookup to fold arbitrary host/header/attribute dictionary keys. Native adapters also reject ambiguous aliases before adding private state.

Implementation

Object? readXraySchemaField(Map<String, dynamic> object, String field) {
  final wanted = foldXraySchemaField(field);
  Object? value;
  var present = false;
  for (final entry in object.entries) {
    if (foldXraySchemaField(entry.key) != wanted) continue;
    if (present) {
      throw ArgumentError('Xray config has conflicting aliases for "$field"');
    }
    present = true;
    value = entry.value;
  }
  return value;
}