post<T> static method

Future<T> post<T>({
  1. required String url,
  2. dynamic body,
  3. String? contentType,
  4. Map<String, String>? headers,
  5. Map<String, dynamic>? query,
  6. bool showDefaultLoading = true,
  7. ProgressCallback? onSendProgress,
  8. ProgressCallback? onReceiveProgress,
  9. Duration? sendTimeout,
  10. 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);
}