findSchemas method Null safety

Future<List<SchemaDefinition>> findSchemas(
  1. {String? creator}
)

Find a Schema Definition

Searches for all schemas owned by the provided creator. If creator is not provided it defaults to the MotorFlutter.address. Returns a List of SchemaDefinition if succesful. Returns an empty List if no definition is found.

final schemas = await MotorFlutter.to.findSchemas(creator: 'did:snr:abc123');
if (schemas == null) {
 throw Exception('Failed to find schema');
}
// Output: {'MySchema': {label: 'MySchema', fields: {name: String, age: Int}}, 'MyOtherSchema': {label: 'MyOtherSchema', fields: {name: String, age: Int}}}

Next Steps

Implementation

Future<List<SchemaDefinition>> findSchemas({String? creator}) async {
  final res = await MotorFlutterPlatform.instance.querySchemaByCreator(QueryWhatIsByCreatorRequest(creator: creator ?? address.value));
  if (res == null) {
    Log.error("Failed to find any schemas made by the provided DID ${creator ?? address.value}");
    return [];
  }
  final schemaMap = res.schemas;
  return schemaMap.entries.map<SchemaDefinition>((e) => e.value).toList();
}