|  |  |  | @ -2,21 +2,25 @@ import 'dart:async'; | 
		
	
		
			
				|  |  |  |  | import 'dart:convert'; | 
		
	
		
			
				|  |  |  |  | import 'dart:developer'; | 
		
	
		
			
				|  |  |  |  | import 'dart:io' show Platform; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/material.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/api_consts.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/app_state.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/dependencies.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/utils/utils.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/services/dialog_service.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/services/logger_service.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:http/http.dart' as http; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import '../exceptions/api_failure.dart'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | abstract class ApiClient { | 
		
	
		
			
				|  |  |  |  |   Future<void> post( | 
		
	
		
			
				|  |  |  |  |     String endPoint, { | 
		
	
		
			
				|  |  |  |  |     required Map<String, dynamic> body, | 
		
	
		
			
				|  |  |  |  |     required Function(dynamic response, int statusCode) onSuccess, | 
		
	
		
			
				|  |  |  |  |     required Function(String error, int statusCode) onFailure, | 
		
	
		
			
				|  |  |  |  |     required Function(dynamic response, int statusCode, {int? messageStatus}) onSuccess, | 
		
	
		
			
				|  |  |  |  |     required Function(String error, int statusCode, {int? messageStatus, Failure? failureType}) onFailure, | 
		
	
		
			
				|  |  |  |  |     bool isAllowAny, | 
		
	
		
			
				|  |  |  |  |     bool isExternal, | 
		
	
		
			
				|  |  |  |  |     bool isRCService, | 
		
	
	
		
			
				
					|  |  |  | @ -32,61 +36,69 @@ abstract class ApiClient { | 
		
	
		
			
				|  |  |  |  |     bool isRCService, | 
		
	
		
			
				|  |  |  |  |   }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> simplePost( | 
		
	
		
			
				|  |  |  |  |     String fullUrl, { | 
		
	
		
			
				|  |  |  |  |     required Map<dynamic, dynamic> body, | 
		
	
		
			
				|  |  |  |  |     required Map<String, String> headers, | 
		
	
		
			
				|  |  |  |  |     required Function(dynamic response, int statusCode) onSuccess, | 
		
	
		
			
				|  |  |  |  |     required Function(String error, int statusCode) onFailure, | 
		
	
		
			
				|  |  |  |  |   }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> simpleGet( | 
		
	
		
			
				|  |  |  |  |     String fullUrl, { | 
		
	
		
			
				|  |  |  |  |     Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |     Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  |     Map<String, dynamic>? queryParams, | 
		
	
		
			
				|  |  |  |  |     Map<String, String>? headers, | 
		
	
		
			
				|  |  |  |  |   }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> simplePut( | 
		
	
		
			
				|  |  |  |  |     String fullUrl, { | 
		
	
		
			
				|  |  |  |  |     Map<String, dynamic>? body, | 
		
	
		
			
				|  |  |  |  |     Map<String, String>? headers, | 
		
	
		
			
				|  |  |  |  |     Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |     Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  |   }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> simpleDelete( | 
		
	
		
			
				|  |  |  |  |     String fullUrl, { | 
		
	
		
			
				|  |  |  |  |     Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |     Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  |     Map<String, String>? queryParams, | 
		
	
		
			
				|  |  |  |  |     Map<String, String>? headers, | 
		
	
		
			
				|  |  |  |  |   }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<bool> handleUnauthorized(int statusCode, {required String forUrl}); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   String getSessionId(String id); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<String> generatePackagesToken(); | 
		
	
		
			
				|  |  |  |  | // Future<void> simplePost( | 
		
	
		
			
				|  |  |  |  | //   String fullUrl, { | 
		
	
		
			
				|  |  |  |  | //   required Map<dynamic, dynamic> body, | 
		
	
		
			
				|  |  |  |  | //   required Map<String, String> headers, | 
		
	
		
			
				|  |  |  |  | //   required Function(dynamic response, int statusCode) onSuccess, | 
		
	
		
			
				|  |  |  |  | //   required Function(String error, int statusCode) onFailure, | 
		
	
		
			
				|  |  |  |  | // }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | // | 
		
	
		
			
				|  |  |  |  | // Future<void> simpleGet( | 
		
	
		
			
				|  |  |  |  | //   String fullUrl, { | 
		
	
		
			
				|  |  |  |  | //   Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  | //   Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  | //   Map<String, dynamic>? queryParams, | 
		
	
		
			
				|  |  |  |  | //   Map<String, String>? headers, | 
		
	
		
			
				|  |  |  |  | // }); | 
		
	
		
			
				|  |  |  |  | // | 
		
	
		
			
				|  |  |  |  | // Future<void> simplePut( | 
		
	
		
			
				|  |  |  |  | //   String fullUrl, { | 
		
	
		
			
				|  |  |  |  | //   Map<String, dynamic>? body, | 
		
	
		
			
				|  |  |  |  | //   Map<String, String>? headers, | 
		
	
		
			
				|  |  |  |  | //   Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  | //   Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  | // }); | 
		
	
		
			
				|  |  |  |  | // | 
		
	
		
			
				|  |  |  |  | // Future<void> simpleDelete( | 
		
	
		
			
				|  |  |  |  | //   String fullUrl, { | 
		
	
		
			
				|  |  |  |  | //   Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  | //   Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  | //   Map<String, String>? queryParams, | 
		
	
		
			
				|  |  |  |  | //   Map<String, String>? headers, | 
		
	
		
			
				|  |  |  |  | // }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | // Future<bool> handleUnauthorized(int statusCode, {required String forUrl}); | 
		
	
		
			
				|  |  |  |  | // Future<String> generatePackagesToken(); | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |   final _analytics = getIt<GAnalytics>(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   final LoggerService loggerService; | 
		
	
		
			
				|  |  |  |  |   final AppState appState; | 
		
	
		
			
				|  |  |  |  |   final DialogService dialogService; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   ApiClientImp({required this.loggerService}); | 
		
	
		
			
				|  |  |  |  |   ApiClientImp({ | 
		
	
		
			
				|  |  |  |  |     required this.loggerService, | 
		
	
		
			
				|  |  |  |  |     required this.dialogService, | 
		
	
		
			
				|  |  |  |  |     required this.appState, | 
		
	
		
			
				|  |  |  |  |   }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   @override | 
		
	
		
			
				|  |  |  |  |   post(String endPoint, | 
		
	
		
			
				|  |  |  |  |       {required Map<String, dynamic> body, | 
		
	
		
			
				|  |  |  |  |       required Function(dynamic response, int statusCode) onSuccess, | 
		
	
		
			
				|  |  |  |  |       required Function(String error, int statusCode) onFailure, | 
		
	
		
			
				|  |  |  |  |       bool isAllowAny = false, | 
		
	
		
			
				|  |  |  |  |       bool isExternal = false, | 
		
	
		
			
				|  |  |  |  |       bool isRCService = false, | 
		
	
		
			
				|  |  |  |  |       bool bypassConnectionCheck = false}) async { | 
		
	
		
			
				|  |  |  |  |   post( | 
		
	
		
			
				|  |  |  |  |     String endPoint, { | 
		
	
		
			
				|  |  |  |  |     required Map<String, dynamic> body, | 
		
	
		
			
				|  |  |  |  |     required Function(dynamic response, int statusCode, {int? messageStatus}) onSuccess, | 
		
	
		
			
				|  |  |  |  |     required Function(String error, int statusCode, {int? messageStatus, Failure? failureType}) onFailure, | 
		
	
		
			
				|  |  |  |  |     bool isAllowAny = false, | 
		
	
		
			
				|  |  |  |  |     bool isExternal = false, | 
		
	
		
			
				|  |  |  |  |     bool isRCService = false, | 
		
	
		
			
				|  |  |  |  |     bool bypassConnectionCheck = false, | 
		
	
		
			
				|  |  |  |  |   }) async { | 
		
	
		
			
				|  |  |  |  |     AppState appState = getIt.get<AppState>(); | 
		
	
		
			
				|  |  |  |  |     String url; | 
		
	
		
			
				|  |  |  |  |     if (isExternal) { | 
		
	
	
		
			
				
					|  |  |  | @ -103,7 +115,7 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |       Map<String, String> headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}; | 
		
	
		
			
				|  |  |  |  |       if (!isExternal) { | 
		
	
		
			
				|  |  |  |  |         String? token = appState.appAuthToken; | 
		
	
		
			
				|  |  |  |  |         String? languageID = (appState.postParamsObject?.languageID == 1 ? 'ar' : 'en') ?? 'ar'; | 
		
	
		
			
				|  |  |  |  |         String? languageID = (appState.postParamsObject?.languageID == 1 ? 'ar' : 'en'); | 
		
	
		
			
				|  |  |  |  |         if (endPoint == ApiConsts.sendActivationCode) { | 
		
	
		
			
				|  |  |  |  |           languageID = 'en'; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
	
		
			
				
					|  |  |  | @ -113,7 +125,6 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         if (body.containsKey('LanguageID')) { | 
		
	
		
			
				|  |  |  |  |           if (body['LanguageID'] != null) { | 
		
	
		
			
				|  |  |  |  |             //change this line because language issue happened on dental | 
		
	
		
			
				|  |  |  |  |             body['LanguageID'] = body['LanguageID'] == 'ar' | 
		
	
		
			
				|  |  |  |  |                 ? 1 | 
		
	
		
			
				|  |  |  |  |                 : body['LanguageID'] == 'en' | 
		
	
	
		
			
				
					|  |  |  | @ -128,7 +139,6 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |               : IS_DENTAL_ALLOWED_BACKEND; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         //Todo:  I have converted it to string | 
		
	
		
			
				|  |  |  |  |         body['DeviceTypeID'] = Platform.isIOS | 
		
	
		
			
				|  |  |  |  |             ? "1" | 
		
	
	
		
			
				
					|  |  |  | @ -160,40 +170,38 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       body['LanguageID']   = body['LanguageID'] ?? "2"; | 
		
	
		
			
				|  |  |  |  |       body['VersionID']    = body['VersionID'] ?? "18.7"; | 
		
	
		
			
				|  |  |  |  |       body['Channel']      = body['Channel'] ?? "3"; | 
		
	
		
			
				|  |  |  |  |       body['IPAdress']     = body['IPAdress'] ?? "10.20.10.20"; | 
		
	
		
			
				|  |  |  |  |       body['generalid']    = body['generalid'] ?? "Cs2020@2016\$2958"; | 
		
	
		
			
				|  |  |  |  |       body['Latitude']     = body['Latitude'] ?? "0.0"; | 
		
	
		
			
				|  |  |  |  |       body['Longitude']    = body['Longitude'] ?? "0.0"; | 
		
	
		
			
				|  |  |  |  |       body['LanguageID'] = body['LanguageID'] ?? "2"; | 
		
	
		
			
				|  |  |  |  |       body['VersionID'] = body['VersionID'] ?? "18.7"; | 
		
	
		
			
				|  |  |  |  |       body['Channel'] = body['Channel'] ?? "3"; | 
		
	
		
			
				|  |  |  |  |       body['IPAdress'] = body['IPAdress'] ?? "10.20.10.20"; | 
		
	
		
			
				|  |  |  |  |       body['generalid'] = body['generalid'] ?? "Cs2020@2016\$2958"; | 
		
	
		
			
				|  |  |  |  |       body['Latitude'] = body['Latitude'] ?? "0.0"; | 
		
	
		
			
				|  |  |  |  |       body['Longitude'] = body['Longitude'] ?? "0.0"; | 
		
	
		
			
				|  |  |  |  |       body['DeviceTypeID'] = body['DeviceTypeID'] ?? | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |           (Platform.isIOS ? "1" : await Utils.isGoogleServicesAvailable() ? "2" : "3"); | 
		
	
		
			
				|  |  |  |  |       //"LanguageID":1,"VersionID":18.7,"Channel":3,"IPAdress":"10.20.10.20","generalid":"Cs2020@2016$2958","Latitude":0.0,"Longitude":0.0,"DeviceTypeID":2,"PatientType":1} | 
		
	
		
			
				|  |  |  |  |           (Platform.isIOS | 
		
	
		
			
				|  |  |  |  |               ? "1" | 
		
	
		
			
				|  |  |  |  |               : await Utils.isGoogleServicesAvailable() | 
		
	
		
			
				|  |  |  |  |                   ? "2" | 
		
	
		
			
				|  |  |  |  |                   : "3"); | 
		
	
		
			
				|  |  |  |  |       body.removeWhere((key, value) => value == null); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       log("bodi: ${json.encode(body)}"); | 
		
	
		
			
				|  |  |  |  |       log("bodi: ${Uri.parse(url.trim())}"); | 
		
	
		
			
				|  |  |  |  |       log("body: ${json.encode(body)}"); | 
		
	
		
			
				|  |  |  |  |       log("uri: ${Uri.parse(url.trim())}"); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       if (await Utils.checkConnection(bypassConnectionCheck: bypassConnectionCheck)) { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         final response = await http.post(Uri.parse(url.trim()), body: json.encode(body), headers: headers); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |         if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |           onFailure('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |           onFailure('Error While Fetching data', statusCode, failureType: ServerFailure("Error While Fetching data")); | 
		
	
		
			
				|  |  |  |  |           logApiEndpointError(endPoint, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |           var parsed =  json.decode(utf8.decode(response.bodyBytes)); | 
		
	
		
			
				|  |  |  |  |           var parsed = json.decode(utf8.decode(response.bodyBytes)); | 
		
	
		
			
				|  |  |  |  |           log("parsed: ${parsed.toString()}"); | 
		
	
		
			
				|  |  |  |  |           if (isAllowAny) { | 
		
	
		
			
				|  |  |  |  |             onSuccess(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |           } else { | 
		
	
		
			
				|  |  |  |  |             if (parsed['Response_Message'] != null) { | 
		
	
		
			
				|  |  |  |  |               onSuccess(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |               onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus']); | 
		
	
		
			
				|  |  |  |  |             } else { | 
		
	
		
			
				|  |  |  |  |               if (parsed['ErrorType'] == 4) { | 
		
	
		
			
				|  |  |  |  |                 //TODO : handle app update | 
		
	
	
		
			
				
					|  |  |  | @ -204,19 +212,18 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |                 logApiEndpointError(endPoint, "session logged out", statusCode); | 
		
	
		
			
				|  |  |  |  |               } | 
		
	
		
			
				|  |  |  |  |               if (isAllowAny) { | 
		
	
		
			
				|  |  |  |  |                 onSuccess(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |                 onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus']); | 
		
	
		
			
				|  |  |  |  |               } else if (parsed['IsAuthenticated'] == null) { | 
		
	
		
			
				|  |  |  |  |                 if (parsed['isSMSSent'] == true) { | 
		
	
		
			
				|  |  |  |  |                   onSuccess(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |                   onSuccess(parsed, statusCode, messageStatus: parsed['MessageStatus']); | 
		
	
		
			
				|  |  |  |  |                 } else if (parsed['MessageStatus'] == 1) { | 
		
	
		
			
				|  |  |  |  |                   onSuccess(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |                 } else if (parsed['Result'] == 'OK') { | 
		
	
		
			
				|  |  |  |  |                   onSuccess(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |                 } else { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |                   onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode); | 
		
	
		
			
				|  |  |  |  |                   onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode, | 
		
	
		
			
				|  |  |  |  |                       failureType: ServerFailure("Error While Fetching data")); | 
		
	
		
			
				|  |  |  |  |                   logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |                 } | 
		
	
		
			
				|  |  |  |  |               } else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) { | 
		
	
		
			
				|  |  |  |  |                 onSuccess(parsed, statusCode); | 
		
	
	
		
			
				
					|  |  |  | @ -226,28 +233,46 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |                 } else { | 
		
	
		
			
				|  |  |  |  |                   if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) { | 
		
	
		
			
				|  |  |  |  |                     if (parsed['ErrorSearchMsg'] == null) { | 
		
	
		
			
				|  |  |  |  |                       onFailure("Server Error found with no available message", statusCode); | 
		
	
		
			
				|  |  |  |  |                       onFailure( | 
		
	
		
			
				|  |  |  |  |                         "Server Error found with no available message", | 
		
	
		
			
				|  |  |  |  |                         statusCode, | 
		
	
		
			
				|  |  |  |  |                         failureType: ServerFailure("Error While Fetching data"), | 
		
	
		
			
				|  |  |  |  |                       ); | 
		
	
		
			
				|  |  |  |  |                       logApiEndpointError(endPoint, "Server Error found with no available message", statusCode); | 
		
	
		
			
				|  |  |  |  |                     } else { | 
		
	
		
			
				|  |  |  |  |                       onFailure(parsed['ErrorSearchMsg'], statusCode); | 
		
	
		
			
				|  |  |  |  |                       onFailure( | 
		
	
		
			
				|  |  |  |  |                         parsed['ErrorSearchMsg'], | 
		
	
		
			
				|  |  |  |  |                         statusCode, | 
		
	
		
			
				|  |  |  |  |                         failureType: ServerFailure("Error While Fetching data"), | 
		
	
		
			
				|  |  |  |  |                       ); | 
		
	
		
			
				|  |  |  |  |                       logApiEndpointError(endPoint, parsed['ErrorSearchMsg'], statusCode); | 
		
	
		
			
				|  |  |  |  |                     } | 
		
	
		
			
				|  |  |  |  |                   } else { | 
		
	
		
			
				|  |  |  |  |                     onFailure(parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode); | 
		
	
		
			
				|  |  |  |  |                     onFailure( | 
		
	
		
			
				|  |  |  |  |                       parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], | 
		
	
		
			
				|  |  |  |  |                       statusCode, | 
		
	
		
			
				|  |  |  |  |                       failureType: ServerFailure("Error While Fetching data"), | 
		
	
		
			
				|  |  |  |  |                     ); | 
		
	
		
			
				|  |  |  |  |                     logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode); | 
		
	
		
			
				|  |  |  |  |                   } | 
		
	
		
			
				|  |  |  |  |                 } | 
		
	
		
			
				|  |  |  |  |               } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |               else { | 
		
	
		
			
				|  |  |  |  |               } else { | 
		
	
		
			
				|  |  |  |  |                 if (parsed['SameClinicApptList'] != null) { | 
		
	
		
			
				|  |  |  |  |                   onSuccess(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |                 } else { | 
		
	
		
			
				|  |  |  |  |                   if (parsed['message'] != null) { | 
		
	
		
			
				|  |  |  |  |                     onFailure(parsed['message'] ?? parsed['message'], statusCode); | 
		
	
		
			
				|  |  |  |  |                     onFailure( | 
		
	
		
			
				|  |  |  |  |                       parsed['message'] ?? parsed['message'], | 
		
	
		
			
				|  |  |  |  |                       statusCode, | 
		
	
		
			
				|  |  |  |  |                       failureType: ServerFailure("Error While Fetching data"), | 
		
	
		
			
				|  |  |  |  |                     ); | 
		
	
		
			
				|  |  |  |  |                     logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode); | 
		
	
		
			
				|  |  |  |  |                   } else { | 
		
	
		
			
				|  |  |  |  |                     onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode); | 
		
	
		
			
				|  |  |  |  |                     onFailure( | 
		
	
		
			
				|  |  |  |  |                       parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], | 
		
	
		
			
				|  |  |  |  |                       statusCode, | 
		
	
		
			
				|  |  |  |  |                       failureType: ServerFailure("Error While Fetching data"), | 
		
	
		
			
				|  |  |  |  |                     ); | 
		
	
		
			
				|  |  |  |  |                     logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode); | 
		
	
		
			
				|  |  |  |  |                   } | 
		
	
		
			
				|  |  |  |  |                 } | 
		
	
	
		
			
				
					|  |  |  | @ -256,13 +281,17 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |           } | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         onFailure('Please Check The Internet Connection 1', -1); | 
		
	
		
			
				|  |  |  |  |         onFailure( | 
		
	
		
			
				|  |  |  |  |           'Please Check The Internet Connection 1', | 
		
	
		
			
				|  |  |  |  |           -1, | 
		
	
		
			
				|  |  |  |  |           failureType: ConnectivityFailure("Error While Fetching data"), | 
		
	
		
			
				|  |  |  |  |         ); | 
		
	
		
			
				|  |  |  |  |         _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } catch (e) { | 
		
	
		
			
				|  |  |  |  |       loggerService.errorLogs(e.toString()); | 
		
	
		
			
				|  |  |  |  |       if (e.toString().contains("ClientException")) { | 
		
	
		
			
				|  |  |  |  |         onFailure('Something went wrong, plase try again', -1); | 
		
	
		
			
				|  |  |  |  |         onFailure('Something went wrong, plase try again', -1, failureType: InvalidCredentials('Something went wrong, plase try again')); | 
		
	
		
			
				|  |  |  |  |         _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         onFailure(e.toString(), -1); | 
		
	
	
		
			
				
					|  |  |  | @ -271,6 +300,7 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   @override | 
		
	
		
			
				|  |  |  |  |   get(String endPoint, | 
		
	
		
			
				|  |  |  |  |       {required Function(dynamic response, int statusCode) onSuccess, | 
		
	
		
			
				|  |  |  |  |       required Function(String error, int statusCode) onFailure, | 
		
	
	
		
			
				
					|  |  |  | @ -304,203 +334,173 @@ class ApiClientImp implements ApiClient { | 
		
	
		
			
				|  |  |  |  |       // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |         onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |         onFailure('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |         logApiEndpointError(endPoint, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         var parsed = json.decode(utf8.decode(response.bodyBytes)); | 
		
	
		
			
				|  |  |  |  |         onSuccess!(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |       _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   simplePost( | 
		
	
		
			
				|  |  |  |  |     String fullUrl, { | 
		
	
		
			
				|  |  |  |  |     required Map<dynamic, dynamic> body, | 
		
	
		
			
				|  |  |  |  |     required Map<String, String> headers, | 
		
	
		
			
				|  |  |  |  |     required Function(dynamic response, int statusCode) onSuccess, | 
		
	
		
			
				|  |  |  |  |     required Function(String error, int statusCode) onFailure, | 
		
	
		
			
				|  |  |  |  |   }) async { | 
		
	
		
			
				|  |  |  |  |     String url = fullUrl; | 
		
	
		
			
				|  |  |  |  |     // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  |     // print("body: $body"); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (await Utils.checkConnection()) { | 
		
	
		
			
				|  |  |  |  |       headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'}); | 
		
	
		
			
				|  |  |  |  |       final response = await http.post( | 
		
	
		
			
				|  |  |  |  |         Uri.parse(url.trim()), | 
		
	
		
			
				|  |  |  |  |         body: json.encode(body), | 
		
	
		
			
				|  |  |  |  |         headers: headers, | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  |       final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |       // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  |       if (await handleUnauthorized(statusCode, forUrl: fullUrl)) | 
		
	
		
			
				|  |  |  |  |         simplePost(fullUrl, onFailure: onFailure, onSuccess: onSuccess, body: body, headers: headers); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       // print(response.body.toString()); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |         onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |         logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         onSuccess!(response.body.toString(), statusCode); | 
		
	
		
			
				|  |  |  |  |         onSuccess(parsed, statusCode); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |       onFailure('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |       _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   simpleGet(String fullUrl, | 
		
	
		
			
				|  |  |  |  |       {Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |       Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  |       Map<String, dynamic>? queryParams, | 
		
	
		
			
				|  |  |  |  |       Map<String, String>? headers}) async { | 
		
	
		
			
				|  |  |  |  |     headers = headers ?? {}; | 
		
	
		
			
				|  |  |  |  |     String url = fullUrl; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     var haveParams = (queryParams != null); | 
		
	
		
			
				|  |  |  |  |     if (haveParams) { | 
		
	
		
			
				|  |  |  |  |       String queryString = Uri(queryParameters: queryParams).query; | 
		
	
		
			
				|  |  |  |  |       url += '?$queryString'; | 
		
	
		
			
				|  |  |  |  |       // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (await Utils.checkConnection()) { | 
		
	
		
			
				|  |  |  |  |       headers.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'}); | 
		
	
		
			
				|  |  |  |  |       final response = await http.get( | 
		
	
		
			
				|  |  |  |  |         Uri.parse(url.trim()), | 
		
	
		
			
				|  |  |  |  |         headers: headers, | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |       // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  |       if (await handleUnauthorized(statusCode, forUrl: fullUrl)) | 
		
	
		
			
				|  |  |  |  |         simpleGet(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, queryParams: queryParams); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |         onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |         logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         onSuccess!(response.body.toString(), statusCode); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |       _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   simplePut(String fullUrl, | 
		
	
		
			
				|  |  |  |  |       {Map<String, dynamic>? body, | 
		
	
		
			
				|  |  |  |  |       Map<String, String>? headers, | 
		
	
		
			
				|  |  |  |  |       Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |       Function(String error, int statusCode)? onFailure}) async { | 
		
	
		
			
				|  |  |  |  |     String url = fullUrl; | 
		
	
		
			
				|  |  |  |  |     // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (await Utils.checkConnection()) { | 
		
	
		
			
				|  |  |  |  |       headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'}); | 
		
	
		
			
				|  |  |  |  |       final response = await http.put( | 
		
	
		
			
				|  |  |  |  |         Uri.parse(url.trim()), | 
		
	
		
			
				|  |  |  |  |         body: json.encode(body), | 
		
	
		
			
				|  |  |  |  |         headers: headers, | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |       // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  |       if (await handleUnauthorized(statusCode, forUrl: fullUrl)) | 
		
	
		
			
				|  |  |  |  |         simplePut(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, body: body); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |         onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |         logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         onSuccess!(response.body.toString(), statusCode); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |       _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   simpleDelete(String fullUrl, | 
		
	
		
			
				|  |  |  |  |       {Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |       Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  |       Map<String, String>? queryParams, | 
		
	
		
			
				|  |  |  |  |       Map<String, String>? headers}) async { | 
		
	
		
			
				|  |  |  |  |     String url = fullUrl; | 
		
	
		
			
				|  |  |  |  |     // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     var haveParams = (queryParams != null); | 
		
	
		
			
				|  |  |  |  |     if (haveParams) { | 
		
	
		
			
				|  |  |  |  |       String queryString = Uri(queryParameters: queryParams).query; | 
		
	
		
			
				|  |  |  |  |       url += '?$queryString'; | 
		
	
		
			
				|  |  |  |  |       // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (await Utils.checkConnection()) { | 
		
	
		
			
				|  |  |  |  |       headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'}); | 
		
	
		
			
				|  |  |  |  |       final response = await http.delete( | 
		
	
		
			
				|  |  |  |  |         Uri.parse(url.trim()), | 
		
	
		
			
				|  |  |  |  |         headers: headers, | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |       // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  |       if (await handleUnauthorized(statusCode, forUrl: fullUrl)) | 
		
	
		
			
				|  |  |  |  |         simpleDelete(fullUrl, onFailure: onFailure, onSuccess: onSuccess, queryParams: queryParams, headers: headers); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |         onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |         logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         onSuccess!(response.body.toString(), statusCode); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |       _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<bool> handleUnauthorized(int statusCode, {required String forUrl}) async { | 
		
	
		
			
				|  |  |  |  |     if (forUrl.startsWith(EXA_CART_API_BASE_URL) && statusCode == 401) { | 
		
	
		
			
				|  |  |  |  |       final token = await generatePackagesToken(); | 
		
	
		
			
				|  |  |  |  |       ApiConsts.packagesAuthHeader['Authorization'] = 'Bearer $token'; | 
		
	
		
			
				|  |  |  |  |       return (token is String); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     return false; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  |   // @override | 
		
	
		
			
				|  |  |  |  |   // simplePost( | 
		
	
		
			
				|  |  |  |  |   //   String fullUrl, { | 
		
	
		
			
				|  |  |  |  |   //   required Map<dynamic, dynamic> body, | 
		
	
		
			
				|  |  |  |  |   //   required Map<String, String> headers, | 
		
	
		
			
				|  |  |  |  |   //   required Function(dynamic response, int statusCode) onSuccess, | 
		
	
		
			
				|  |  |  |  |   //   required Function(String error, int statusCode) onFailure, | 
		
	
		
			
				|  |  |  |  |   // }) async { | 
		
	
		
			
				|  |  |  |  |   //   String url = fullUrl; | 
		
	
		
			
				|  |  |  |  |   //   // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  |   //   // print("body: $body"); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //   if (await Utils.checkConnection()) { | 
		
	
		
			
				|  |  |  |  |   //     headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'}); | 
		
	
		
			
				|  |  |  |  |   //     final response = await http.post( | 
		
	
		
			
				|  |  |  |  |   //       Uri.parse(url.trim()), | 
		
	
		
			
				|  |  |  |  |   //       body: json.encode(body), | 
		
	
		
			
				|  |  |  |  |   //       headers: headers, | 
		
	
		
			
				|  |  |  |  |   //     ); | 
		
	
		
			
				|  |  |  |  |   //     final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |   //     // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  |   //     if (await handleUnauthorized(statusCode, forUrl: fullUrl)) { | 
		
	
		
			
				|  |  |  |  |   //       simplePost(fullUrl, onFailure: onFailure, onSuccess: onSuccess, body: body, headers: headers); | 
		
	
		
			
				|  |  |  |  |   //     } | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //     // print(response.body.toString()); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //     if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |   //       onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |   //       logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |   //     } else { | 
		
	
		
			
				|  |  |  |  |   //       onSuccess!(response.body.toString(), statusCode); | 
		
	
		
			
				|  |  |  |  |   //     } | 
		
	
		
			
				|  |  |  |  |   //   } else { | 
		
	
		
			
				|  |  |  |  |   //     onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |   //     _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |   //   } | 
		
	
		
			
				|  |  |  |  |   // } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   // simpleGet(String fullUrl, | 
		
	
		
			
				|  |  |  |  |   //     {Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |   //     Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  |   //     Map<String, dynamic>? queryParams, | 
		
	
		
			
				|  |  |  |  |   //     Map<String, String>? headers}) async { | 
		
	
		
			
				|  |  |  |  |   //   headers = headers ?? {}; | 
		
	
		
			
				|  |  |  |  |   //   String url = fullUrl; | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //   var haveParams = (queryParams != null); | 
		
	
		
			
				|  |  |  |  |   //   if (haveParams) { | 
		
	
		
			
				|  |  |  |  |   //     String queryString = Uri(queryParameters: queryParams).query; | 
		
	
		
			
				|  |  |  |  |   //     url += '?$queryString'; | 
		
	
		
			
				|  |  |  |  |   //     // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  |   //   } | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //   if (await Utils.checkConnection()) { | 
		
	
		
			
				|  |  |  |  |   //     headers.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'}); | 
		
	
		
			
				|  |  |  |  |   //     final response = await http.get( | 
		
	
		
			
				|  |  |  |  |   //       Uri.parse(url.trim()), | 
		
	
		
			
				|  |  |  |  |   //       headers: headers, | 
		
	
		
			
				|  |  |  |  |   //     ); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //     final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |   //     // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  |   //     if (await handleUnauthorized(statusCode, forUrl: fullUrl)) | 
		
	
		
			
				|  |  |  |  |   //       simpleGet(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, queryParams: queryParams); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //     if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |   //       onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |   //       logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |   //     } else { | 
		
	
		
			
				|  |  |  |  |   //       onSuccess!(response.body.toString(), statusCode); | 
		
	
		
			
				|  |  |  |  |   //     } | 
		
	
		
			
				|  |  |  |  |   //   } else { | 
		
	
		
			
				|  |  |  |  |   //     onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |   //     _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |   //   } | 
		
	
		
			
				|  |  |  |  |   // } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   // simplePut(String fullUrl, | 
		
	
		
			
				|  |  |  |  |   //     {Map<String, dynamic>? body, | 
		
	
		
			
				|  |  |  |  |   //     Map<String, String>? headers, | 
		
	
		
			
				|  |  |  |  |   //     Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |   //     Function(String error, int statusCode)? onFailure}) async { | 
		
	
		
			
				|  |  |  |  |   //   String url = fullUrl; | 
		
	
		
			
				|  |  |  |  |   //   // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //   if (await Utils.checkConnection()) { | 
		
	
		
			
				|  |  |  |  |   //     headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'}); | 
		
	
		
			
				|  |  |  |  |   //     final response = await http.put( | 
		
	
		
			
				|  |  |  |  |   //       Uri.parse(url.trim()), | 
		
	
		
			
				|  |  |  |  |   //       body: json.encode(body), | 
		
	
		
			
				|  |  |  |  |   //       headers: headers, | 
		
	
		
			
				|  |  |  |  |   //     ); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //     final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |   //     // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  |   //     if (await handleUnauthorized(statusCode, forUrl: fullUrl)) | 
		
	
		
			
				|  |  |  |  |   //       simplePut(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, body: body); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //     if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |   //       onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |   //       logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |   //     } else { | 
		
	
		
			
				|  |  |  |  |   //       onSuccess!(response.body.toString(), statusCode); | 
		
	
		
			
				|  |  |  |  |   //     } | 
		
	
		
			
				|  |  |  |  |   //   } else { | 
		
	
		
			
				|  |  |  |  |   //     onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |   //     _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |   //   } | 
		
	
		
			
				|  |  |  |  |   // } | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   // simpleDelete(String fullUrl, | 
		
	
		
			
				|  |  |  |  |   //     {Function(dynamic response, int statusCode)? onSuccess, | 
		
	
		
			
				|  |  |  |  |   //     Function(String error, int statusCode)? onFailure, | 
		
	
		
			
				|  |  |  |  |   //     Map<String, String>? queryParams, | 
		
	
		
			
				|  |  |  |  |   //     Map<String, String>? headers}) async { | 
		
	
		
			
				|  |  |  |  |   //   String url = fullUrl; | 
		
	
		
			
				|  |  |  |  |   //   // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //   var haveParams = (queryParams != null); | 
		
	
		
			
				|  |  |  |  |   //   if (haveParams) { | 
		
	
		
			
				|  |  |  |  |   //     String queryString = Uri(queryParameters: queryParams).query; | 
		
	
		
			
				|  |  |  |  |   //     url += '?$queryString'; | 
		
	
		
			
				|  |  |  |  |   //     // print("URL Query String: $url"); | 
		
	
		
			
				|  |  |  |  |   //   } | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //   if (await Utils.checkConnection()) { | 
		
	
		
			
				|  |  |  |  |   //     headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'}); | 
		
	
		
			
				|  |  |  |  |   //     final response = await http.delete( | 
		
	
		
			
				|  |  |  |  |   //       Uri.parse(url.trim()), | 
		
	
		
			
				|  |  |  |  |   //       headers: headers, | 
		
	
		
			
				|  |  |  |  |   //     ); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //     final int statusCode = response.statusCode; | 
		
	
		
			
				|  |  |  |  |   //     // print("statusCode :$statusCode"); | 
		
	
		
			
				|  |  |  |  |   //     if (await handleUnauthorized(statusCode, forUrl: fullUrl)) | 
		
	
		
			
				|  |  |  |  |   //       simpleDelete(fullUrl, onFailure: onFailure, onSuccess: onSuccess, queryParams: queryParams, headers: headers); | 
		
	
		
			
				|  |  |  |  |   // | 
		
	
		
			
				|  |  |  |  |   //     if (statusCode < 200 || statusCode >= 400) { | 
		
	
		
			
				|  |  |  |  |   //       onFailure!('Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |   //       logApiFullUrlError(fullUrl, 'Error While Fetching data', statusCode); | 
		
	
		
			
				|  |  |  |  |   //     } else { | 
		
	
		
			
				|  |  |  |  |   //       onSuccess!(response.body.toString(), statusCode); | 
		
	
		
			
				|  |  |  |  |   //     } | 
		
	
		
			
				|  |  |  |  |   //   } else { | 
		
	
		
			
				|  |  |  |  |   //     onFailure!('Please Check The Internet Connection', -1); | 
		
	
		
			
				|  |  |  |  |   //     _analytics.errorTracking.log("internet_connectivity", error: "no internet available"); | 
		
	
		
			
				|  |  |  |  |   //   } | 
		
	
		
			
				|  |  |  |  |   // } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   @override | 
		
	
		
			
				|  |  |  |  |   String getSessionId(String id) { | 
		
	
		
			
				|  |  |  |  |     return id.replaceAll(RegExp('/[^a-zA-Z]'), ''); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<String> generatePackagesToken() async { | 
		
	
		
			
				|  |  |  |  |     var url = EXA_CART_API_BASE_URL + PACKAGES_TOKEN; | 
		
	
		
			
				|  |  |  |  |     var body = { | 
		
	
		
			
				|  |  |  |  |       "api_client": { | 
		
	
		
			
				|  |  |  |  |         "client_id": "a4ab6be4-424f-4836-b032-46caed88e184", | 
		
	
		
			
				|  |  |  |  |         "client_secret": "3c1a3e07-4a40-4510-9fb0-ee5f0a72752c" | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  |     String? token; | 
		
	
		
			
				|  |  |  |  |     final completer = Completer(); | 
		
	
		
			
				|  |  |  |  |     simplePost(url, body: body, headers: {}, onSuccess: (dynamic stringResponse, int statusCode) { | 
		
	
		
			
				|  |  |  |  |       if (statusCode == 200) { | 
		
	
		
			
				|  |  |  |  |         var jsonResponse = json.decode(stringResponse); | 
		
	
		
			
				|  |  |  |  |         token = jsonResponse['auth_token']; | 
		
	
		
			
				|  |  |  |  |         completer.complete(); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     }, onFailure: (String error, int statusCode) { | 
		
	
		
			
				|  |  |  |  |       completer.complete(); | 
		
	
		
			
				|  |  |  |  |       logApiFullUrlError(url, error, statusCode); | 
		
	
		
			
				|  |  |  |  |     }); | 
		
	
		
			
				|  |  |  |  |     await completer.future; | 
		
	
		
			
				|  |  |  |  |     return token!; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   logApiFullUrlError(String fullUrl, error, code) { | 
		
	
		
			
				|  |  |  |  |     final endpoint = Uri.parse(fullUrl).pathSegments.last; | 
		
	
		
			
				|  |  |  |  |     logApiEndpointError(endpoint, error, code); | 
		
	
	
		
			
				
					|  |  |  | 
 |