sendToServer method

  1. @override
Future<void> sendToServer({
  1. required String url,
  2. required String methodType,
  3. Map<String, String>? headers,
  4. Object? body,
  5. Encoding? encoding,
})
override

Send error reports to a server.

This method sends error reports to a specified url using the given methodType. Additional parameters like headers, body, encoding, and supressCustomErrors can be specified.

url is the target URL for sending error reports.

methodType is the HTTP method type for the request (e.g., 'POST').

headers are optional HTTP headers to include in the request.

body is the request body, which can be of type String or Map.

encoding is the character encoding to use for the request.

Implementation

@override
Future<void> sendToServer(
    {required String url,
    required String methodType,
    Map<String, String>? headers,
    Object? body,
    Encoding? encoding}) async {
  final uri = Uri.parse(url);

  if (methodType.toLowerCase() == CustomErrorConstants.POST) {
    final response = await http.post(uri,
        headers: headers ?? {}, body: body, encoding: encoding ?? utf8);

    _isStatusOk(response);
  } else if (methodType.toLowerCase() == CustomErrorConstants.GET) {
    final response = await http.get(
      uri,
      headers: headers ?? {},
    );

    _isStatusOk(response);
  } else {
    _printTextWithIcon(
      '${CustomErrorConstants.CUSTOM_ERROR}: methodType not supported.',
      TextColor.red,
      BackgroundColor.transparent,
      Icon.unicodeError,
      TextStyle.blink,
      paddingLeft: 2, // Left padding
      paddingTop: 10, // Top padding
      paddingRight: 2, // Right padding
      paddingBottom: 10, // Bottom padding
    );
  }
}