findBucket method Null safety
Find a Schema Definition
Queries the Sonr blockchain for the associated WhereIs for the provided did
or creator
. If did
is provided a single-value list is returned (if successful), and the creator
argument will be ignored.
Returns List<WhereIs>
if bucket(s) are found. Returns null if no bucket is found, or if neither did
nor creator
were provided.
// Search by DID
final buckets = await MotorFlutter.to.findBucket(did: 'did:snr:xyz789');
if (buckets == null) {
throw Exception('Failed to find bucket');
}
// Search by creator
final buckets = await MotorFlutter.to.findBucket(creator: 'did:snr:abc123');
if (buckets == null) {
throw Exception('Failed to find bucket');
}
Next Steps
- Read the Arch Diagram for our Storage Module on ADR-3
Implementation
Future<List<Bucket>> findBucket({String? did, String? creator}) async {
if (did != null) {
final res = await MotorFlutterPlatform.instance.queryBucket(QueryWhereIsRequest(did: did));
if (res != null) {
return [Bucket.fromWhereIs(res.whereIs)];
}
}
if (creator != null) {
final res = await MotorFlutterPlatform.instance.queryBucketByCreator(QueryWhereIsByCreatorRequest(creator: creator));
if (res != null) {
return Bucket.fromWhereIsList(res.whereIs);
}
}
return [];
}