findSchemas method Null safety
Searches for a schema by either its did
or creator
. If did
is provided a single-value map is returned, and the creator
argument will be ignored. Returns a map of String to SchemaDefinition if definition(s) are found. Returns
null if no definition is found, or if neither did
nor creator
were provided.
Example
// Search by DID
final schemas = await MotorFlutter.to.findSchemas(did: 'did:snr:xyz789');
if (schemas == null) {
throw Exception('Failed to find schema');
}
print(schemas); // prints: {'MySchema': {label: 'MySchema', fields: {name: String, age: Int}}}
// Search by creator
final schemas = await MotorFlutter.to.findSchemas(creator: 'did:snr:abc123');
if (schemas == null) {
throw Exception('Failed to find schema');
}
print(schemas); // prints: {'MySchema': {label: 'MySchema', fields: {name: String, age: Int}}, 'MyOtherSchema': {label: 'MyOtherSchema', fields: {name: String, age: Int}}}
Next Steps:
- Build a SchemaDocument from a Definition with SchemaDefinitionExt
- ADR-3
Implementation
Future<Map<String, SchemaDefinition>?> findSchemas({String? did, String? creator}) async {
if (did != null) {
final res = await MotorFlutterPlatform.instance.querySchema(QueryWhatIsRequest(did: did));
if (res != null) {
return {res.schema.label: res.schema};
}
}
final res = await MotorFlutterPlatform.instance.querySchemaByCreator(QueryWhatIsByCreatorRequest(creator: creator ?? address.value));
if (res != null) {
return res.schemas;
}
return null;
}