BaseApi<T> constructor
BaseApi<T> ({
- String path = '',
- dynamic param,
- Map<
String, dynamic> ? queryParameters, - bool isDebug = true,
- Options? opt,
- 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,
- bool showToast = true,
- bool showLoading = true,
- bool encrypt = false,
- 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());
}