send method Null safety

Future<String> send(
  1. Uri uri,
  2. String requestData
)

Send the SOAP requestData to the given url endpoint.

Implementation

static Future<String> send(Uri uri, String requestData) async {
  Response? response;

  try {
    response = await _http.post(uri.toString(),
        data: requestData,
        options: Options(headers: {
          Headers.contentTypeHeader: 'application/soap+xml; charset=utf-8',
          Headers.contentLengthHeader: requestData.length
        }));
  } on DioError catch (error) {
    if (error.response?.statusCode == 500 ||
        error.response?.statusCode == 400) {
      final jsonMap = OnvifUtil.xmlToMap(error.response?.data);

      final envelope = Envelope.fromJson(jsonMap);

      if (envelope.body.hasFault) {
        throw Exception('Error code: ${envelope.body.fault}');
      }
    }

    throw Exception(error);
  }

  return response.data;
}