getSchema method Null safety

Future<SchemaDefinition?> getSchema(
  1. 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

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;
}