add method Null safety
- SchemaDocument doc
Adds a SchemaDocument into the Bucket and returns bool indicating success
Implementation
Future<BucketItem?> add(SchemaDocument doc) async {
await refresh();
final label = doc.label;
final req = UploadDocumentRequest(
schemaDid: doc.schemaDid,
label: label,
document: doc.writeToJson().codeUnits,
);
if (isDebugMode) {
print('Adding document to bucket: ${req.toString()}');
}
final resp = await MotorFlutterPlatform.instance.uploadDocument(req);
if (resp == null) {
return null;
}
final item = BucketItem(
uri: resp.cid,
name: label,
type: ResourceIdentifier.CID,
schemaDid: doc.schemaDid,
);
final ok = await MotorFlutterPlatform.instance.addBucketObject(did, item);
if (ok) {
return item;
}
return null;
}