uploadDocument method Null safety

Future<UploadDocumentResponse> uploadDocument(
  1. {required SchemaDocument doc,
  2. required String label}
)

Upload a Document

Uploads a document to IPFS. Returns the UploadDocumentResponse if successful, and null if the document was not found.

// Define a document
final def = SchemaDefinition(label: 'MySchema', fields: {'name': 'String', 'age': 'Int'});

// Create empty document from definition
final doc = def.newDocument();
doc.set<String>('name', 'John');
doc.set<int>('age', 30);

// Upload document to IPFS
final res = await MotorFlutter.to.uploadDocument(doc);
if (res == null) {
 throw Exception('Failed to upload document');
}

Next Steps

Implementation

Future<UploadDocumentResponse> uploadDocument({required SchemaDocument doc, required String label}) async {
  final res = await MotorFlutterPlatform.instance.uploadDocument(UploadDocumentRequest(
    creator: address.value,
    definition: doc.definition,
    fields: doc.fields,
    label: label,
  ));
  if (res == null) {
    throw UnmarshalException<UploadDocumentResponse>();
  }
  return res;
}