refresh method Null safety

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

This function will refresh the stats for the current user, and if a callback is provided, it will be called with the response.

Args: callback (ResponseCallback): A callback function that will be called when the response is received.

Implementation

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

  // Wrap instance method with try catch
  try {
    final resp = await MotorFlutterPlatform.instance.stat();
    if (resp != null) {
      didDocument(resp.didDocument);
      address(resp.address);
      domain(resp.didDocument.alsoKnownAs.isNotEmpty ? resp.didDocument.alsoKnownAs[0] : "test.snr/");
      balance(resp.balance);
      didUrl(resp.didDocument.id);
      staked(resp.stake.toString());
    }
    if (callback != null) {
      callback(resp);
    }
    return resp;
  } catch (e) {
    Log.printMotorException(e.toString());
  }
  return null;
}