postRequest function

Future postRequest(
  1. BuildContext context,
  2. String url,
  3. dynamic data, {
  4. bool showProgressIndicator = true,
  5. Map? headers,
})

Implementation

Future postRequest(BuildContext context, String url, dynamic data,
    {bool showProgressIndicator = true, Map? headers}) {
  Map customHeaders = headers != null ? headers : {};
  return dio
      .post(url,
          data: data,
          options: Options(headers: {
            ...customHeaders as Map<String, dynamic>
          }))
      .catchError((err) {
    showSnackBar(context, "Sorry an error occurred");
  }).catchError((err) {
    if (showProgressIndicator) showSnackBar(context, "Sorry an error occurred");
    print(err);
  });
}