request<T> method
Future<T>
request<
T>( - String url, {
- String? baseUrl,
- String? method,
- Options? options,
- dynamic data,
- bool showLoading = false,
- CancelToken? cancelToken,
- void onSendProgress(
- int,
- int
)?,
- void onReceiveProgress(
- int,
- int
)?,
})
Implementation
Future<T> request<T>(
String url, {
String? baseUrl,
String? method,
Options? options,
data,
bool showLoading = false,
CancelToken? cancelToken,
void Function(int, int)? onSendProgress,
void Function(int, int)? onReceiveProgress,
}) async {
try {
options ??= Options();
options.method =
method?.toUpperCase() ?? HttpMethod.get.name.toUpperCase();
if (showLoading) {
CommonHelper.showLoading();
}
Response response = await _dio.request(
baseUrl != null ? baseUrl + url : this.baseUrl + url,
data: data,
queryParameters:
options.method == HttpMethod.get.name.toUpperCase() ? data : null,
options: options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
if (showLoading) {
CommonHelper.hideLoading();
}
return response.data;
} catch (e) {
if (showLoading) {
CommonHelper.hideLoading();
}
throw e.toString();
}
}