fix : dio call
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/infrastructure/remote/interfaces/i_form_data.dart';
|
||||
|
||||
import 'dio_form_data.dart';
|
||||
import 'dio_response.dart';
|
||||
import 'interfaces/i_http_client.dart';
|
||||
|
||||
class DioRemote implements IHttpClient {
|
||||
@@ -29,7 +28,7 @@ class DioRemote implements IHttpClient {
|
||||
Map<String, String>? headers,
|
||||
ProgressCallback? onReceiveProgress,
|
||||
}) async {
|
||||
final response = await _dio.get<T>(
|
||||
final response = await _dio.get(
|
||||
path,
|
||||
queryParameters: queryParameters,
|
||||
options: Options(headers: headers),
|
||||
@@ -48,7 +47,7 @@ class DioRemote implements IHttpClient {
|
||||
ProgressCallback? onSendProgress,
|
||||
ProgressCallback? onReceiveProgress,
|
||||
}) async {
|
||||
final response = await _dio.post<T>(
|
||||
final response = await _dio.post(
|
||||
path,
|
||||
data: data,
|
||||
queryParameters: queryParameters,
|
||||
@@ -57,6 +56,8 @@ class DioRemote implements IHttpClient {
|
||||
onReceiveProgress: onReceiveProgress,
|
||||
);
|
||||
|
||||
eLog(response.toString());
|
||||
|
||||
if (fromJson != null) {
|
||||
final rawData = response.data;
|
||||
final parsedData =
|
||||
@@ -65,7 +66,7 @@ class DioRemote implements IHttpClient {
|
||||
return DioResponse<T>(response);
|
||||
}
|
||||
|
||||
return DioResponse<T>(response);
|
||||
return DioResponse<T>(response );
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -77,7 +78,7 @@ class DioRemote implements IHttpClient {
|
||||
ProgressCallback? onSendProgress,
|
||||
ProgressCallback? onReceiveProgress,
|
||||
}) async {
|
||||
final response = await _dio.put<T>(
|
||||
final response = await _dio.put(
|
||||
path,
|
||||
data: data,
|
||||
queryParameters: queryParameters,
|
||||
@@ -124,7 +125,7 @@ class DioRemote implements IHttpClient {
|
||||
Map<String, String>? headers,
|
||||
ProgressCallback? onSendProgress,
|
||||
}) async {
|
||||
final response = await _dio.post<T>(
|
||||
final response = await _dio.post(
|
||||
path,
|
||||
data: (formData as DioFormData).raw,
|
||||
options: Options(headers: headers, contentType: 'multipart/form-data'),
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'interfaces/i_http_response.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class DioResponse<T> implements IHttpResponse<T> {
|
||||
final Response<T> _response;
|
||||
final Response<dynamic> _response;
|
||||
|
||||
DioResponse(this._response);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
typedef AsyncCallback<T> = Future<T> Function();
|
||||
typedef ErrorCallback = void Function(dynamic error, StackTrace? stackTrace);
|
||||
@@ -27,12 +28,14 @@ Future<T?> safeCall<T>({
|
||||
|
||||
final result = await call();
|
||||
|
||||
iLog(result.toString());
|
||||
|
||||
if (showSuccess) {
|
||||
(onShowSuccessMessage ?? _defaultShowSuccessMessage)();
|
||||
}
|
||||
|
||||
onSuccess?.call(result);
|
||||
return result; // اضافه کردن بازگشت نتیجه
|
||||
return result;
|
||||
|
||||
} catch (error, stackTrace) {
|
||||
if (showError) {
|
||||
|
||||
Reference in New Issue
Block a user