getValue<T> method
Null safety
Returns the underlying value of the SchemaDocumentValue as the provided T
type. If the value cannot be cast to the provided type, or the provided T
doesnt match SchemaKind, then null is returned.
final doc = SchemaDocument();
String? name = "";
for (final field in doc.fields) {
if(field.name == 'name') {
name = field.getValue<String>(); // returns the value of the field 'name' as a String
}
}
if (name != null) {
print(name); // prints the value of the field 'name'
}
Implementation
T? getValue<T>() {
switch (field_2) {
case SchemaKind.BOOL:
if (T is bool) {
return boolValue.value as T;
}
break;
case SchemaKind.INT:
if (T is int) {
return intValue.value as T;
}
break;
case SchemaKind.FLOAT:
if (T is double) {
return floatValue.value as T;
}
break;
case SchemaKind.STRING:
if (T is String) {
return stringValue.value as T;
}
break;
case SchemaKind.BYTES:
if (T is Uint8List) {
return bytesValue.value as T;
}
break;
case SchemaKind.LIST:
if (T is List) {
return arrayValue.value as T;
}
break;
case SchemaKind.LINK:
if (T is String) {
return linkValue.value as T;
}
break;
default:
break;
}
return null;
}