import 'package:dio/dio.dart'; import 'package:syncrow_web/services/api/api_links_endpoints.dart'; import 'package:syncrow_web/services/api/http_interceptor.dart'; import 'package:syncrow_web/services/locator.dart'; class HTTPService { final Dio client = serviceLocator.get(); // final navigatorKey = GlobalKey(); String certificateString = ""; static Dio setupDioClient() { Dio client = Dio( BaseOptions( baseUrl: ApiEndpoints.baseUrl, receiveDataWhenStatusError: true, followRedirects: false, connectTimeout: const Duration(seconds: 30), receiveTimeout: const Duration(seconds: 30), ), ); client.interceptors.add(serviceLocator.get()); return client; } Future get({ required String path, Map? queryParameters, required T Function(dynamic) expectedResponseModel, bool showServerMessage = true, }) async { try { final response = await client.get( path, queryParameters: queryParameters, ); return expectedResponseModel(response.data); } catch (error) { rethrow; } } Future post( {required String path, Map? queryParameters, Options? options, dynamic body, bool showServerMessage = true, required T Function(dynamic) expectedResponseModel}) async { try { final response = await client.post( path, data: body, queryParameters: queryParameters, options: options, ); return expectedResponseModel(response.data); } catch (error) { rethrow; } } Future patch( {required String path, Map? queryParameters, dynamic body, required T Function(dynamic) expectedResponseModel}) async { try { final response = await client.patch( path, data: body, queryParameters: queryParameters, ); return expectedResponseModel(response.data); } catch (error) { rethrow; } } Future put( {required String path, Map? queryParameters, dynamic body, required T Function(dynamic) expectedResponseModel}) async { try { final response = await client.put( path, data: body, queryParameters: queryParameters, ); return expectedResponseModel(response.data); } catch (error) { rethrow; } } Future download( {required String path, required String savePath, Map? queryParameters, required T Function(dynamic) expectedResponseModel}) async { try { final response = await client.download( path, savePath, onReceiveProgress: (current, total) {}, ); return expectedResponseModel(response.data); // return expectedResponseModel(response.data); } catch (error) { rethrow; } } Future delete({ required String path, Map? queryParameters, required T Function(dynamic) expectedResponseModel, bool showServerMessage = true, }) async { try { final response = await client.delete( path, queryParameters: queryParameters, ); return expectedResponseModel(response.data); } catch (error) { rethrow; } } }