BaseApi<T> constructor

BaseApi<T>({
  1. String path = '',
  2. dynamic param,
  3. Map<String, dynamic>? queryParameters,
  4. bool isDebug = true,
  5. Options? opt,
  6. String method = 'POST',
  7. Duration? sendTimeout,
  8. Duration? receiveTimeout,
  9. ResponseType? responseType,
  10. String? contentType,
  11. ValidateStatus? validateStatus,
  12. bool? receiveDataWhenStatusError,
  13. bool? followRedirects,
  14. int? maxRedirects,
  15. RequestEncoder? requestEncoder,
  16. ResponseDecoder? responseDecoder,
  17. ListFormat? listFormat,
  18. bool showToast = true,
  19. bool showLoading = true,
  20. bool encrypt = false,
  21. TransformJson<T>? serializer,
})

Implementation

BaseApi(
    {this.path = '',
    this.param,

    /// url?a=''&b=''
    this.queryParameters,
    this.isDebug = true,

    ///  custom opt
    Options? opt,

    /// refer to [Options]
    String method = 'POST',
    Duration? sendTimeout,
    Duration? receiveTimeout,
    ResponseType? responseType,
    String? contentType,
    ValidateStatus? validateStatus,
    bool? receiveDataWhenStatusError,
    bool? followRedirects,
    int? maxRedirects,
    RequestEncoder? requestEncoder,
    ResponseDecoder? responseDecoder,
    ListFormat? listFormat,

    ///  auto show toast when network error or [BaseModel.isSuccess]  is false
    bool showToast = true,

    /// auto show loading when request
    bool showLoading = true,
    bool encrypt = false,
    this.serializer})
    : this.opt = opt ??
          Options(
              method: method,
              sendTimeout: sendTimeout,
              receiveTimeout: receiveTimeout,
              responseType: responseType,
              contentType: contentType,
              validateStatus: validateStatus,
              receiveDataWhenStatusError: receiveDataWhenStatusError,
              followRedirects: followRedirects,
              maxRedirects: maxRedirects,
              requestEncoder: requestEncoder,
              responseDecoder: responseDecoder,
              listFormat: listFormat) {
  this.canShowLoading = showLoading;
  this.canShowToast = showToast;
  this.isEncrypt = encrypt;
  assert(requestBaseUrl().length > 0);
  DioManager().dio.options.baseUrl = requestBaseUrl();
  (this.opt.extra ??= Map<String, dynamic>()).addAll({"BaseApi": this});
  (this.opt.headers ??= Map<String, dynamic>()).addAll(requestHeader());
}