setValue<T> method
T?
setValue<T>(
- T v
Sets the value of the SchemaDocumentValue to the provided value
. If the provided T
doesnt match Kind, 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 (kind) {
case Kind.BOOL:
if (v is bool) {
boolValue = BoolValue(value: v);
return v;
}
break;
case Kind.INT:
if (v is int) {
intValue = IntValue(value: v);
return v;
}
break;
case Kind.FLOAT:
if (v is double) {
floatValue = FloatValue(value: v);
return v;
}
break;
case Kind.STRING:
if (v is String) {
stringValue = StringValue(value: v);
return v;
}
break;
case Kind.BYTES:
if (v is Uint8List) {
bytesValue = BytesValue(value: v);
return v;
}
break;
case Kind.LIST:
if (v is List<SchemaDocumentValue>) {
listValue = ListValue(value: v);
return v;
}
break;
case Kind.LINK:
if (v is SchemaDocument) {
linkValue = LinkValue(value: v);
return v;
}
break;
default:
break;
}
return null;
}