set<T> method

T? set<T>(
  1. String name,
  2. T value
)

Sets the provided T value to the SchemaDocument for the given name of the field. Returns true if the field was found and set, false otherwise.

final doc = SchemaDocument();
final res = doc.set<String>('name', 'John Doe'); // sets the value of the field 'name' to 'John Doe'

Implementation

T? set<T>(String name, T value) {
  final field = fields.firstWhereOrNull((e) => e.key == name);
  if (field == null) {
    throw Exception('Field not found');
  }
  return field.setValue<T>(value);
}