findBucket method Null safety

Future<List<WhereIs>?> findBucket(
  1. {String? did,
  2. String? creator}
)

Description

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.

Example

// 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:

Implementation

Future<List<WhereIs>?> findBucket({String? did, String? creator}) async {
  if (did != null) {
    final res = await MotorFlutterPlatform.instance.queryBucket(QueryWhereIsRequest(did: did));
    if (res != null) {
      return [res.whereIs];
    }
  }

  if (creator != null) {
    final res = await MotorFlutterPlatform.instance.queryBucketByCreator(QueryWhereIsByCreatorRequest(creator: creator));
    if (res != null) {
      return res.whereIs;
    }
  }
  return null;
}