refresh method Null safety

Future<StatResponse> refresh(
  1. [ResponseCallback<StatResponse>? callback]
)

Get Account Info

Returns the current Accounts Info and updates the reactive Variables of MotorFlutter.

Values for address, didDocument, balance, didUrl, and staked change with the latest values from the blockchain. An optional callback can be provided to be notified when the refresh is complete.

// Refresh the current account
await MotorFlutter.to.refresh();
print(MotorFlutter.to.address); // prints: 'did:snr:abc123'
print(MotorFlutter.to.balance); // prints: 1000

Next Steps

Implementation

Future<StatResponse> refresh([ResponseCallback<StatResponse>? callback]) async {
  if (!authorized.value) {
    // Log.printWarn("User is not yet authorized");
  }

  final resp = await MotorFlutterPlatform.instance.stat();
  if (resp != null) {
    didDocument(resp.didDocument);
    address(resp.address);
    balance(resp.balance);
    staked(resp.stake.toString());
  }
  if (resp == null) {
    throw UnmarshalException<StatResponse>();
  }
  callback?.call(resp);
  return resp;
}