save method Null safety

Future<SchemaDocument?> save(
  1. String label
)

Saves the SchemaDocument to the current accounts application-specific data store. The account then encrypts the data and effectively becomes the only entity to be able to view the values. A succesful transaction will return a UploadDocumentResponse.

Example

final doc = defs.first.newDocument();
doc.set<String>('name', 'John Doe');
doc.set<int>('age', 42);
doc.set<bool>('isCool', true);

final res = await doc.save('My Profile');
if (res != null) {
   print('Document saved successfully');
}

See Also

Implementation

Future<SchemaDocument?> save(String label) async {
  if (!MotorFlutter.isReady) {
    Log.warn('MotorFlutter has not been initialized. Please call MotorFlutter.init() before using the SDK.');
    return null;
  }
  if (!MotorFlutter.to.authorized.value) {
    Log.warn('MotorFlutter is not authorized. User MotorFlutter.to.createAccount() or MotorFlutter.to.login() to authorize the SDK.');
    return null;
  }

  final resp = await MotorFlutterPlatform.instance.uploadDocument(UploadDocumentRequest(
    creator: MotorFlutter.to.address.value,
    fields: fields,
    label: label,
    definition: definition,
  ));
  if (resp == null) {
    return null;
  }
  MotorFlutter.to.schemaMap[label] = resp.document;
  return resp.document;
}