getSchema method Null safety
- String did
Search for a Schema Definition
Queries for the associated SchemaDefinition
from the provided did
on the Sonr Blockchain.
Returns SchemaDefinition
if succesfull and null if the Document was not found.
// Search by DID
final schemas = await MotorFlutter.to.getSchema('did:snr:xyz789');
if (schemas == null) {
throw Exception('Failed to find schema');
}
print(schemas); // prints: {'MySchema': {label: 'MySchema', fields: {name: String, age: Int}}}
Next Steps
- Build a SchemaDocument from a Definition with SchemaDefinitionExt
- ADR-3
Implementation
Future<SchemaDefinition?> getSchema(String did) async {
final res = await MotorFlutterPlatform.instance.querySchema(QueryWhatIsRequest(did: did));
if (res == null) {
Log.warn("Failed to query blockchain for provided schema: $did");
return null;
}
return res.schema;
}