post<T> method
Makes an HTTP POST request with an exposed onSendProgress
.
Implementation
Future<dio.Response<T>> post<T>(
dynamic data, {
dio.Options? options,
String? operationName,
Exception Function(Map<String, dynamic>)? onException,
void Function(int, int)? onSendProgress,
}) {
return _middleware(() async {
return await _transaction(operationName, () async {
final dio.Options authorized = options ?? dio.Options();
authorized.headers = (authorized.headers ?? {});
authorized.headers!['Authorization'] = 'Bearer $token';
try {
return await (await PlatformUtils.dio).post<T>(
'${Config.url}:${Config.port}${Config.graphql}',
data: data,
options: authorized,
onSendProgress: onSendProgress,
);
} on dio.DioException catch (e) {
if (e.response != null) {
if (onException != null &&
e.response?.data is Map<String, dynamic> &&
e.response?.data['data'] != null) {
throw onException(e.response!.data['data']);
}
}
rethrow;
}
});
});
}