getStorageNoncePublicKey function Null safety

Future<String> getStorageNoncePublicKey(
  1. String endpoint
)

Implementation

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

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

  try {
    const String _body =
        '{"query": "query {sharedSecrets {storageNoncePublicKey}}"}';
    print(_body);
    final 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;
}