pull method Null safety

Future<SchemaDocument?> pull(
  1. {String? cid}
)

Description

Pulls the SchemaDocument from the current accounts application-specific data store using the provided cid. The account then decrypts the data and its values are returned as a SchemaDocument. A succesful transaction will return a SchemaDocument.

Example

final cid = MotorFlutter.to.getCIDForDid('did:3:...');
final doc = await SchemaDocument.pull(cid);
if (doc != null) {
  print('Document pulled successfully');
}

Implementation

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

  try {
    final resp = await MotorFlutterPlatform.instance.getDocument(GetDocumentRequest(
      cid: cid ?? MotorFlutter.to.getCIDForDid(did),
    ));
    if (resp == null) {
      return null;
    }
    return resp.document;
  } catch (e) {
    Log.printFlutterWarn(e.toString());
    return null;
  }
}