ApiRequest constructor

ApiRequest({
  1. required BuildContext context,
  2. required ApiCallBackListener apiCallBackListener,
  3. required String httpType,
  4. required String url,
  5. required String apiAction,
  6. Map<String, String>? headers,
  7. Map<String, String>? body,
  8. Encoding? encoding,
  9. bool? isMultiPart,
  10. Color? progressBarColors,
  11. bool? showLoader,
  12. Map<String, File>? mapOfFilesAndKey,
  13. Function? logoutFunction,
  14. String? apiTimeOutMsg,
  15. String? errorMessage,
})

Implementation

ApiRequest(
    {required this.context,
      required this.apiCallBackListener,
      required this.httpType,
      required this.url,
      required this.apiAction,
      this.headers,
    this.body,
    this.encoding,
    this.isMultiPart,
    this.progressBarColors,
    this.showLoader,
    this.mapOfFilesAndKey,
    this.logoutFunction,
    this.apiTimeOutMsg,
    this.errorMessage
    }) {
  print("url=="+url.toString()+"\nshowLoader=="+showLoader.toString());
  if (context != null) {
    CommonFile.checkInternetConnectivity().then((bool isConnected) async {
      if (isConnected) {
        try {
          ProgressDialog.show(context,progressBarColors??Colors.black,showLoader??false);
          // headers = getApiHeader(accessToken);
          if (isMultiPart != null && isMultiPart==true) {
            getAPIMultiRequest(url,
                headers: headers,
                body: body,
                encoding: encoding,
                mapOfFilesAndKey: mapOfFilesAndKey);
          } else {
            getAPIRequest(url,
                headers: headers, body: body, encoding: encoding);
          }
        } catch (onError) {
          print(onError.toString());
        }
      } else {
        CommonFile.showToastMessage("No Internet Connection.");
      }
    });
  }
}