getStorageNoncePublicKey function Null safety

Future<String> getStorageNoncePublicKey(
  1. String endpoint
)

Implementation

Future<String> getStorageNoncePublicKey(String endpoint) async {
  Completer<String> _completer = new Completer<String>();
  String _storageNoncePublicKey = "";
  SharedSecretsResponse sharedSecretsResponse = new SharedSecretsResponse();

  final Map<String, String> requestHeaders = {
    'Content-type': 'application/json',
    'Accept': 'application/json',
  };

  try {
    String _body = '{"query": "query {sharedSecrets {storageNoncePublicKey}}"}';
    print(_body);
    http.Response responseHttp = await http.post(Uri.parse(endpoint + '/api'),
        body: _body, headers: requestHeaders);
    print(responseHttp.body);
    if (responseHttp.statusCode == 200) {
      sharedSecretsResponse = sharedSecretsResponseFromJson(responseHttp.body);
      if (sharedSecretsResponse.data != null &&
          sharedSecretsResponse.data!.sharedSecrets != null) {
        _storageNoncePublicKey =
            sharedSecretsResponse.data!.sharedSecrets!.storageNoncePublicKey!;
      }
    }
  } catch (e) {
    print("error: " + e.toString());
  }

  _completer.complete(_storageNoncePublicKey);
  return _completer.future;
}