From 9146655f0ebedf44315fe0d22f0a6612de3db5a7 Mon Sep 17 00:00:00 2001 From: moktadir Date: Thu, 28 Mar 2024 07:38:46 +0600 Subject: [PATCH] added interceptor --- lib/app/service/REST/dio_client.dart | 27 +++++++++++++++++++-------- pubspec.lock | 8 ++++++++ pubspec.yaml | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/app/service/REST/dio_client.dart b/lib/app/service/REST/dio_client.dart index cd03e53..ea27eb5 100755 --- a/lib/app/service/REST/dio_client.dart +++ b/lib/app/service/REST/dio_client.dart @@ -5,16 +5,27 @@ import 'dart:convert'; import 'dart:io'; import 'package:dio/dio.dart'; +import 'package:pretty_dio_logger/pretty_dio_logger.dart'; import 'api_header.dart'; class DioClient { static const int TIME_OUT_DURATION = 10; - BaseOptions baseOptions = BaseOptions( + + final _dio = Dio(BaseOptions( connectTimeout: const Duration(seconds: TIME_OUT_DURATION), receiveTimeout: const Duration(seconds: TIME_OUT_DURATION), sendTimeout: const Duration(seconds: TIME_OUT_DURATION), - ); + )) + ..interceptors.add(PrettyDioLogger( + requestHeader: true, + requestBody: true, + responseBody: true, + responseHeader: false, + error: true, + compact: true, + maxWidth: 90, + )); //GET @@ -23,7 +34,7 @@ class DioClient { Map? params, }) async { try { - var response = await Dio(baseOptions).get(url, + var response = await _dio.get(url, options: Options(headers: Header.rapidApiHeader), queryParameters: params); @@ -39,7 +50,7 @@ class DioClient { {required String url, Map? params, dynamic body}) async { var payload = json.encode(body); try { - var response = await Dio(baseOptions).post(url, + var response = await _dio.post(url, options: Options(headers: Header.defaultHeader), queryParameters: params, data: payload); @@ -56,7 +67,7 @@ class DioClient { {required String url, Map? params, dynamic body}) async { var payload = json.encode(body); try { - var response = await Dio(baseOptions).patch(url, + var response = await _dio.patch(url, options: Options(headers: Header.defaultHeader), queryParameters: params, data: payload); @@ -72,7 +83,7 @@ class DioClient { {required String url, Map? params, dynamic body}) async { var payload = json.encode(body); try { - var response = await Dio(baseOptions).delete(url, + var response = await _dio.delete(url, options: Options(headers: Header.defaultHeader), queryParameters: params, data: payload); @@ -100,7 +111,7 @@ class DioClient { } try { - var response = await Dio(baseOptions).post(url, + var response = await _dio.post(url, options: Options(headers: Header.defaultMultipartHeader), queryParameters: params, data: formData); @@ -124,7 +135,7 @@ class DioClient { } try { - var response = await Dio(baseOptions).post(url, + var response = await _dio.post(url, options: Options(headers: Header.defaultMultipartHeader), queryParameters: params, data: formData); diff --git a/pubspec.lock b/pubspec.lock index 9a167c5..2fc5df3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1136,6 +1136,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.5.1" + pretty_dio_logger: + dependency: "direct main" + description: + name: pretty_dio_logger + sha256: "00b80053063935cf9a6190da344c5373b9d0e92da4c944c878ff2fbef0ef6dc2" + url: "https://pub.dev" + source: hosted + version: "1.3.1" pub_semver: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 8e6df9f..579ef1b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,6 +51,7 @@ dependencies: image_picker: ^1.0.4 image_cropper: ^5.0.1 web_socket_channel: ^2.4.0 + pretty_dio_logger: ^1.3.1 dev_dependencies: