getTransactionContent function Null safety

Future<String> getTransactionContent(
  1. String address,
  2. String endpoint
)

Implementation

Future<String> getTransactionContent(String address, String endpoint) async {
  final Completer<String> _completer = Completer<String>();
  String _content = '';
  TransactionContentResponse? transactionContentResponse =
      TransactionContentResponse();

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

  final String _body =
      '{"query":"query { transaction(address: \\"$address\\") { data { content }} }"}';
  print(_body);

  try {
    final http.Response responseHttp = await http.post(
        Uri.parse(endpoint + '/api'),
        body: _body,
        headers: requestHeaders);
    print(responseHttp.body);

    if (responseHttp.statusCode == 200) {
      transactionContentResponse =
          transactionContentResponseFromJson(responseHttp.body);
      if (transactionContentResponse.data != null &&
          transactionContentResponse.data!.transaction != null &&
          transactionContentResponse.data!.transaction!.data != null) {
        _content = transactionContentResponse.data!.transaction!.data!.content!;
      }
    }
  } catch (e) {
    print('error: ' + e.toString());
  }

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