setValue<T> method
Null safety
- T v
Sets the value of the SchemaDocumentValue to the provided value
. If the provided T
doesnt match SchemaKind, then false is returned.
// Create a new document
final doc = SchemaDocument();
// Set the value of the field 'name' to 'John Doe'
for (final field in doc.fields) {
if(field.name == 'name') {
field.setValue<String>("John Doe");
}
}
Implementation
T? setValue<T>(T v) {
if (v == null) {
return null;
}
switch (field_2) {
case SchemaKind.BOOL:
if (v is bool) {
boolValue = BoolValue(value: v);
return v;
}
break;
case SchemaKind.INT:
if (v is int) {
intValue = IntValue(value: v);
return v;
}
break;
case SchemaKind.FLOAT:
if (v is double) {
floatValue = FloatValue(value: v);
return v;
}
break;
case SchemaKind.STRING:
if (v is String) {
stringValue = StringValue(value: v);
return v;
}
break;
case SchemaKind.BYTES:
if (v is Uint8List) {
bytesValue = BytesValue(value: v);
return v;
}
break;
case SchemaKind.LIST:
if (v is List<SchemaDocumentValue>) {
arrayValue = ArrayValue(value: v);
return v;
}
break;
case SchemaKind.LINK:
if (v is String) {
linkValue = LinkValue(value: v);
return v;
}
break;
default:
break;
}
return null;
}