post<T> method

Future<T?> post<T>({
  1. required String url,
  2. Map<String, dynamic>? headers,
  3. Options? options,
  4. Object? data,
  5. dynamic onReceiveProgress(
    1. int,
    2. int
    )?,
  6. CancelToken? cancelToken,
  7. Map<String, dynamic>? queryParameters,
  8. dynamic onError(
    1. dynamic
    )?,
  9. T? responseBuilder(
    1. Response
    )?,
  10. bool withLoading = false,
})

Implementation

Future<T?> post<T>({required final String url,
  Map<String,dynamic>? headers,
 final Options? options,
 Object? data,
 final Function(int,int)? onReceiveProgress,
 CancelToken? cancelToken,
 Map<String, dynamic>? queryParameters,
 final Function(dynamic)? onError,
 final T? Function(Response)? responseBuilder,
 final bool withLoading = false,
  })async {
 final Dio dio = Dio();
 if (queryParameters!=null && queryMapFilter!=null) {
   queryParameters = await queryMapFilter!(queryParameters!);
 }
 if( data != null && dataMapFilter!=null){
   data = await dataMapFilter!(data!);
 }

 headers??=defaultHeaders;

 if(kDebugMode){
   print(""
       "\n sending request to $url with headers $headers");
 }
 final Response? response = await FunctionHelpers.tryFuture<Response>(dio.post(url,
   options: (options?..headers = headers) ?? Options(headers:headers,
   validateStatus:(status)=>true
   ),
   queryParameters:queryParameters,
   cancelToken:cancelToken,
   data:data,
   onReceiveProgress:onReceiveProgress,

 ),
     withLoading:withLoading,
     onError:onError
 );

 if(response!=null ){
  if(kDebugMode) {
    print("$url \n response status is ${response.statusCode} ${response
        .statusMessage}");
    print("data is ${response.data}");
  }
      if(responseBuilder!=null)responseBuilder(response);
      if( onResponseReady!=null && response is! T) return onResponseReady!(response);
 } else {
   if(kDebugMode){
     print("response is null from url ${url}");
   }
 }
 return response as T?;
  }