post<T> static method
Future<T>
post<
T>({ - required String url,
- dynamic body,
- String? contentType,
- Map<String, dynamic>? query,
- bool showDefaultLoading = true,
- ProgressCallback? onSendProgress,
- ProgressCallback? onReceiveProgress,
- Duration? sendTimeout,
- Duration? receiveTimeout,
})
Implementation
static Future<T> post<T>({
required String url,
dynamic body,
String? contentType,
Map<String, String>? headers,
Map<String, dynamic>? query,
bool showDefaultLoading = true,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
Duration? sendTimeout,
Duration? receiveTimeout,
}) {
if (_instance == null) throw Exception('Please call "EasyHttp.init(config)" first.');
return onLoading(() async {
try {
final res = await _dio.post(
url,
data: body,
options: Options(
headers: headers,
contentType: contentType,
sendTimeout: sendTimeout,
receiveTimeout: receiveTimeout,
),
queryParameters: query,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
return T.toString() == "dynamic" ? res.data : EasyHttp.config.cacheSerializer<T>(res.data);
} catch (e) {
rethrow;
}
}, showDefaultLoading: showDefaultLoading);
}