createAccount method Null safety

Future<CreateAccountResponse?> createAccount(
  1. String password,
  2. [ResponseCallback<CreateAccountResponse>? callback]
)

Create a new account with the given password. If the password is correct, the account will be created and the account address will be returned. If the password is incorrect, an error will be returned.

Args: password (String): The password to use for the account. callback (ResponseCallback): A function that takes a CreateAccountResponse as a parameter.

Implementation

Future<CreateAccountResponse?> createAccount(String password, [ResponseCallback<CreateAccountResponse>? callback]) async {
  final dscKey = List<int>.generate(32, (i) => Random().nextInt(256));
  final resp = await MotorFlutterPlatform.instance.createAccount(CreateAccountRequest(
    password: password,
    aesDscKey: dscKey,
  ));
  if (callback != null) {
    callback(resp);
  }
  if (resp != null) {
    address.value = resp.address;
    didUrl.value = resp.whoIs.didDocument.id;
    didDocument.value = resp.whoIs.didDocument;
    authorized.value = true;
  }
  return resp;
}