|
|
|
|
@ -30,8 +30,7 @@ AppSharedPreferences sharedPref = new AppSharedPreferences();
|
|
|
|
|
/// onFailure: (String error, int statusCode) {},
|
|
|
|
|
/// body: Map();
|
|
|
|
|
///
|
|
|
|
|
AuthenticatedUserObject authenticatedUserObject =
|
|
|
|
|
locator<AuthenticatedUserObject>();
|
|
|
|
|
AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
|
|
|
|
|
VitalSignService _vitalSignService = locator<VitalSignService>();
|
|
|
|
|
|
|
|
|
|
class BaseAppClient {
|
|
|
|
|
@ -55,17 +54,12 @@ class BaseAppClient {
|
|
|
|
|
url = BASE_URL + endPoint;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
String? pharmacyToken =
|
|
|
|
|
await sharedPref.getString(PHARMACY_AUTORZIE_TOKEN);
|
|
|
|
|
String? pharmacyToken = await sharedPref.getString(PHARMACY_AUTORZIE_TOKEN);
|
|
|
|
|
var user = await sharedPref.getObject(USER_PROFILE);
|
|
|
|
|
Map<String, String> headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
};
|
|
|
|
|
Map<String, String> headers = {'Content-Type': 'application/json', 'Accept': 'application/json'};
|
|
|
|
|
if (!isExternal) {
|
|
|
|
|
String? token = await sharedPref.getString(TOKEN);
|
|
|
|
|
String? languageID =
|
|
|
|
|
await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
String? languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
if (endPoint == SEND_ACTIVATION_CODE) {
|
|
|
|
|
languageID = 'en';
|
|
|
|
|
}
|
|
|
|
|
@ -81,24 +75,19 @@ class BaseAppClient {
|
|
|
|
|
body['Channel'] = CHANNEL;
|
|
|
|
|
|
|
|
|
|
if (body.containsKey('LanguageID')) {
|
|
|
|
|
|
|
|
|
|
if(body['LanguageID'] != null) {
|
|
|
|
|
if (body['LanguageID'] != null) {
|
|
|
|
|
//change this line because language issue happened on dental
|
|
|
|
|
body['LanguageID'] = body['LanguageID'] =='ar' ? 1 : body['LanguageID'] =='en' ? 2 : body['LanguageID'];
|
|
|
|
|
body['LanguageID'] = body['LanguageID'] == 'ar'
|
|
|
|
|
? 1
|
|
|
|
|
: body['LanguageID'] == 'en'
|
|
|
|
|
? 2
|
|
|
|
|
: body['LanguageID'];
|
|
|
|
|
} else {
|
|
|
|
|
body['LanguageID'] =
|
|
|
|
|
Provider.of<ProjectViewModel>(AppGlobal.context, listen: false)
|
|
|
|
|
.isArabic
|
|
|
|
|
? 1
|
|
|
|
|
: 2;
|
|
|
|
|
body['LanguageID'] = Provider.of<ProjectViewModel>(AppGlobal.context, listen: false).isArabic ? 1 : 2;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// body['LanguageID'] = (languageID.toString().toLowerCase() == 'ar' ? 1 : 2);
|
|
|
|
|
body['LanguageID'] =
|
|
|
|
|
Provider.of<ProjectViewModel>(AppGlobal.context, listen: false)
|
|
|
|
|
.isArabic
|
|
|
|
|
? 1
|
|
|
|
|
: 2;
|
|
|
|
|
body['LanguageID'] = Provider.of<ProjectViewModel>(AppGlobal.context, listen: false).isArabic ? 1 : 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// body['LanguageID'] = Provider.of<ProjectViewModel>(AppGlobal.context, listen: false).isArabic ? 1 : 2;
|
|
|
|
|
@ -114,12 +103,11 @@ class BaseAppClient {
|
|
|
|
|
body['Longitude'] = long;
|
|
|
|
|
|
|
|
|
|
if (body.containsKey('isDentalAllowedBackend')) {
|
|
|
|
|
body['isDentalAllowedBackend'] =
|
|
|
|
|
body.containsKey('isDentalAllowedBackend')
|
|
|
|
|
? body['isDentalAllowedBackend'] != null
|
|
|
|
|
? body['isDentalAllowedBackend']
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND;
|
|
|
|
|
body['isDentalAllowedBackend'] = body.containsKey('isDentalAllowedBackend')
|
|
|
|
|
? body['isDentalAllowedBackend'] != null
|
|
|
|
|
? body['isDentalAllowedBackend']
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body['DeviceTypeID'] = Platform.isIOS
|
|
|
|
|
@ -163,16 +151,15 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
body['TokenID'] = body['TokenID'] != null ? body['TokenID'] : token;
|
|
|
|
|
body['PatientID'] = body['PatientID'] != null
|
|
|
|
|
? body['PatientID']
|
|
|
|
|
: user['PatientID'];
|
|
|
|
|
body['PatientID'] = body['PatientID'] != null ? body['PatientID'] : user['PatientID'];
|
|
|
|
|
|
|
|
|
|
body['PatientOutSA'] = body.containsKey('PatientOutSA')
|
|
|
|
|
? body['PatientOutSA'] != null
|
|
|
|
|
? body['PatientOutSA']
|
|
|
|
|
: user['OutSA']
|
|
|
|
|
: user['OutSA'];
|
|
|
|
|
body['SessionID'] = getSessionId(body['TokenID']); //getSe
|
|
|
|
|
body['SessionID'] = getSessionId(body['TokenID'] != null ? body['TokenID'] : ""); //getSe
|
|
|
|
|
// body['SessionID'] = body['TokenID']; //getSe
|
|
|
|
|
|
|
|
|
|
// headers = {
|
|
|
|
|
// 'Content-Type': 'application/json',
|
|
|
|
|
@ -188,7 +175,7 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
// body['IdentificationNo'] = 1023854217;
|
|
|
|
|
// body['MobileNo'] = "531940021";
|
|
|
|
|
// body['PatientID'] = 291367; //3844083
|
|
|
|
|
// body['PatientID'] = 1400563; //3844083
|
|
|
|
|
// body['TokenID'] = "@dm!n";
|
|
|
|
|
|
|
|
|
|
// Patient ID: 3027574
|
|
|
|
|
@ -203,15 +190,12 @@ class BaseAppClient {
|
|
|
|
|
print(jsonBody);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection(
|
|
|
|
|
bypassConnectionCheck: bypassConnectionCheck)) {
|
|
|
|
|
final response = await http.post(Uri.parse(url.trim()),
|
|
|
|
|
body: json.encode(body), headers: headers);
|
|
|
|
|
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 || json == null) {
|
|
|
|
|
onFailure('Error While Fetching data', statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
// var decoded = utf8.decode(response.bodyBytes);
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
@ -225,12 +209,8 @@ class BaseAppClient {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['ErrorType'] == 4) {
|
|
|
|
|
navigateToAppUpdate(
|
|
|
|
|
AppGlobal.context, parsed['ErrorEndUserMessage']);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
navigateToAppUpdate(AppGlobal.context, parsed['ErrorEndUserMessage']);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
if (parsed['ErrorType'] == 2) {
|
|
|
|
|
await logout();
|
|
|
|
|
@ -249,46 +229,28 @@ class BaseAppClient {
|
|
|
|
|
// if (parsed != null) {
|
|
|
|
|
// onSuccess(parsed, statusCode);
|
|
|
|
|
// } else {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
// logout();
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 ||
|
|
|
|
|
parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 &&
|
|
|
|
|
parsed['IsAuthenticated']) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) {
|
|
|
|
|
if (parsed['SameClinicApptList'] != null) {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['message'] == null &&
|
|
|
|
|
parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
if (parsed['ErrorSearchMsg'] == null) {
|
|
|
|
|
onFailure("Server Error found with no available message",
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
"Server Error found with no available message",
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure("Server Error found with no available message", statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, "Server Error found with no available message", statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure(parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['message'] ??
|
|
|
|
|
parsed['ErrorEndUserMessage'] ??
|
|
|
|
|
parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(endPoint,
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
onFailure(parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -300,18 +262,11 @@ class BaseAppClient {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['message'] != null) {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint,
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
onFailure(parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -320,8 +275,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print(e);
|
|
|
|
|
@ -331,11 +285,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
postPharmacy(String endPoint,
|
|
|
|
|
{Map<String, dynamic>? body,
|
|
|
|
|
Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
Function(String error, int statusCode)? onFailure,
|
|
|
|
|
bool isAllowAny = false,
|
|
|
|
|
bool isExternal = false}) async {
|
|
|
|
|
{Map<String, dynamic>? body, Function(dynamic response, int statusCode)? onSuccess, Function(String error, int statusCode)? onFailure, bool isAllowAny = false, bool isExternal = false}) async {
|
|
|
|
|
var token = await sharedPref.getString(PHARMACY_AUTORZIE_TOKEN);
|
|
|
|
|
var user = await sharedPref.getObject(USER_PROFILE);
|
|
|
|
|
String url;
|
|
|
|
|
@ -352,16 +302,13 @@ class BaseAppClient {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': pharmacyToken ?? '',
|
|
|
|
|
'Mobilenumber': user != null
|
|
|
|
|
? Utils.getPhoneNumberWithoutZero(user['MobileNumber'].toString())
|
|
|
|
|
: "",
|
|
|
|
|
'Mobilenumber': user != null ? Utils.getPhoneNumberWithoutZero(user['MobileNumber'].toString()) : "",
|
|
|
|
|
'Statictoken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
|
|
|
|
|
'Username': user != null ? user['PatientID'].toString() : "",
|
|
|
|
|
};
|
|
|
|
|
if (!isExternal) {
|
|
|
|
|
String token = await sharedPref.getString(TOKEN);
|
|
|
|
|
var languageID =
|
|
|
|
|
await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
|
|
|
|
|
// if (body.containsKey('SetupID')) {
|
|
|
|
|
// body['SetupID'] = body.containsKey('SetupID')
|
|
|
|
|
@ -423,14 +370,12 @@ class BaseAppClient {
|
|
|
|
|
print("Headers : ${json.encode(headers)}");
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
final response = await http.post(Uri.parse(url.trim()),
|
|
|
|
|
body: json.encode(body), headers: headers);
|
|
|
|
|
final response = await http.post(Uri.parse(url.trim()), body: json.encode(body), headers: headers);
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400 || json == null) {
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
// var parsed = json.decode(response.body.toString());
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
@ -438,12 +383,8 @@ class BaseAppClient {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['ErrorType'] == 4) {
|
|
|
|
|
navigateToAppUpdate(
|
|
|
|
|
AppGlobal.context, parsed['ErrorEndUserMessage']);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
navigateToAppUpdate(AppGlobal.context, parsed['ErrorEndUserMessage']);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
if (isAllowAny) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
@ -458,56 +399,29 @@ class BaseAppClient {
|
|
|
|
|
if (parsed != null) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint, 'session logged out', statusCode);
|
|
|
|
|
onFailure!(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, 'session logged out', statusCode);
|
|
|
|
|
logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 ||
|
|
|
|
|
parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 &&
|
|
|
|
|
parsed['IsAuthenticated']) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) {
|
|
|
|
|
if (parsed['SameClinicApptList'] != null) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['message'] == null &&
|
|
|
|
|
parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
if (parsed['ErrorSearchMsg'] == null) {
|
|
|
|
|
onFailure!("Server Error found with no available message",
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
"Server Error found with no available message",
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!("Server Error found with no available message", statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, "Server Error found with no available message", statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!(parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorSearchMsg'] ??
|
|
|
|
|
parsed['ErrorEndUserMessage'] ??
|
|
|
|
|
parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorSearchMsg'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['message'] ??
|
|
|
|
|
parsed['ErrorEndUserMessage'] ??
|
|
|
|
|
parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['message'] ??
|
|
|
|
|
parsed['ErrorEndUserMessage'] ??
|
|
|
|
|
parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!(parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (!parsed['IsAuthenticated']) {
|
|
|
|
|
@ -519,22 +433,11 @@ class BaseAppClient {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['message'] != null) {
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['message'] ??
|
|
|
|
|
parsed['ErrorEndUserMessage'] ??
|
|
|
|
|
parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!(parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -542,8 +445,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print(e);
|
|
|
|
|
@ -555,8 +457,7 @@ class BaseAppClient {
|
|
|
|
|
Future navigateToAppUpdate(context, String text) async {
|
|
|
|
|
Navigator.pushAndRemoveUntil(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => AppUpdatePage(appUpdateText: text)),
|
|
|
|
|
MaterialPageRoute(builder: (context) => AppUpdatePage(appUpdateText: text)),
|
|
|
|
|
(Route<dynamic> route) => false,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@ -587,10 +488,7 @@ class BaseAppClient {
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
final response = await http.get(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
headers: {'Content-Type': 'application/json', 'Accept': 'application/json'},
|
|
|
|
|
);
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
@ -604,8 +502,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -637,9 +534,7 @@ class BaseAppClient {
|
|
|
|
|
'Content-Type': 'text/html; charset=utf-8',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': token ?? '',
|
|
|
|
|
'Mobilenumber': user != null
|
|
|
|
|
? Utils.getPhoneNumberWithoutZero(user['MobileNumber'].toString())
|
|
|
|
|
: "",
|
|
|
|
|
'Mobilenumber': user != null ? Utils.getPhoneNumberWithoutZero(user['MobileNumber'].toString()) : "",
|
|
|
|
|
'Statictoken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
|
|
|
|
|
'Username': user != null ? user['PatientID'].toString() : "",
|
|
|
|
|
// 'Host': "mdlaboratories.com",
|
|
|
|
|
@ -649,19 +544,14 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400 || json == null) {
|
|
|
|
|
if (statusCode == 401) {
|
|
|
|
|
onFailure!(TranslationBase.of(AppGlobal.context).pharmacyRelogin,
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
TranslationBase.of(AppGlobal.context).pharmacyRelogin,
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!(TranslationBase.of(AppGlobal.context).pharmacyRelogin, statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, TranslationBase.of(AppGlobal.context).pharmacyRelogin, statusCode);
|
|
|
|
|
Navigator.of(AppGlobal.context).pushNamed(HOME);
|
|
|
|
|
} else {
|
|
|
|
|
var bodyUtf = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
// print(bodyUtf);
|
|
|
|
|
onFailure!(bodyUtf['error']['ErrorEndUserMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint, bodyUtf['error']['ErrorEndUserMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, bodyUtf['error']['ErrorEndUserMsg'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// var parsed = json.decode(response.body.toString());
|
|
|
|
|
@ -670,8 +560,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -687,8 +576,7 @@ class BaseAppClient {
|
|
|
|
|
// print("body: $body");
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
headers!.addAll(
|
|
|
|
|
{'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.post(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
body: json.encode(body),
|
|
|
|
|
@ -696,12 +584,7 @@ class BaseAppClient {
|
|
|
|
|
);
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl))
|
|
|
|
|
simplePost(fullUrl,
|
|
|
|
|
onFailure: onFailure,
|
|
|
|
|
onSuccess: onSuccess,
|
|
|
|
|
body: body,
|
|
|
|
|
headers: headers);
|
|
|
|
|
if (await handleUnauthorized(statusCode, forUrl: fullUrl)) simplePost(fullUrl, onFailure: onFailure, onSuccess: onSuccess, body: body, headers: headers);
|
|
|
|
|
|
|
|
|
|
// print(response.body.toString());
|
|
|
|
|
|
|
|
|
|
@ -713,16 +596,12 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_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 {
|
|
|
|
|
{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;
|
|
|
|
|
|
|
|
|
|
@ -734,8 +613,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
headers.addAll(
|
|
|
|
|
{'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
headers.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.get(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
headers: headers,
|
|
|
|
|
@ -743,12 +621,7 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
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 (await handleUnauthorized(statusCode, forUrl: fullUrl)) simpleGet(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, queryParams: queryParams);
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400 || json == null) {
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
@ -758,22 +631,17 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_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 {
|
|
|
|
|
{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'});
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.put(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
body: json.encode(body),
|
|
|
|
|
@ -782,12 +650,7 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
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 (await handleUnauthorized(statusCode, forUrl: fullUrl)) simplePut(fullUrl, onFailure: onFailure, onSuccess: onSuccess, headers: headers, body: body);
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400 || json == null) {
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
@ -797,16 +660,12 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_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 {
|
|
|
|
|
{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");
|
|
|
|
|
|
|
|
|
|
@ -818,8 +677,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
headers!.addAll(
|
|
|
|
|
{'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
headers!.addAll({'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.delete(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
headers: headers,
|
|
|
|
|
@ -827,12 +685,7 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
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 (await handleUnauthorized(statusCode, forUrl: fullUrl)) simpleDelete(fullUrl, onFailure: onFailure, onSuccess: onSuccess, queryParams: queryParams, headers: headers);
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400 || json == null) {
|
|
|
|
|
onFailure!('Error While Fetching data', statusCode);
|
|
|
|
|
@ -842,13 +695,11 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> handleUnauthorized(int statusCode,
|
|
|
|
|
{required String forUrl}) async {
|
|
|
|
|
Future<bool> handleUnauthorized(int statusCode, {required String forUrl}) async {
|
|
|
|
|
if (forUrl.startsWith(EXA_CART_API_BASE_URL) && statusCode == 401) {
|
|
|
|
|
final token = await generatePackagesToken();
|
|
|
|
|
packagesAuthHeader['Authorization'] = 'Bearer $token';
|
|
|
|
|
@ -861,10 +712,8 @@ class BaseAppClient {
|
|
|
|
|
await sharedPref.remove(LOGIN_TOKEN_ID);
|
|
|
|
|
await sharedPref.remove(PHARMACY_CUSTOMER_ID);
|
|
|
|
|
await authenticatedUserObject.getUser();
|
|
|
|
|
Provider.of<ProjectViewModel>(AppGlobal.context, listen: false).isLogin =
|
|
|
|
|
false;
|
|
|
|
|
var model =
|
|
|
|
|
Provider.of<ToDoCountProviderModel>(AppGlobal.context, listen: false);
|
|
|
|
|
Provider.of<ProjectViewModel>(AppGlobal.context, listen: false).isLogin = false;
|
|
|
|
|
var model = Provider.of<ToDoCountProviderModel>(AppGlobal.context, listen: false);
|
|
|
|
|
_vitalSignService.weightKg = "";
|
|
|
|
|
_vitalSignService.heightCm = "";
|
|
|
|
|
model.setState(0, 0, false, null);
|
|
|
|
|
@ -873,13 +722,13 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
String getSessionId(String id) {
|
|
|
|
|
///return id.replaceAll(RegExp('/[^\w\s]/'), '');
|
|
|
|
|
// if (id != null) return id.replaceAll(RegExp('/[^a-zA-Z]'), '');
|
|
|
|
|
return id.replaceAll(RegExp('/[^a-zA-Z]'), '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static defaultHttpParameters() async {
|
|
|
|
|
String token = await sharedPref.getString(TOKEN);
|
|
|
|
|
var languageID =
|
|
|
|
|
await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
var user = await sharedPref.getObject(USER_PROFILE);
|
|
|
|
|
var params = {};
|
|
|
|
|
if (user != null) {
|
|
|
|
|
@ -899,11 +748,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pharmacyPost(String endPoint,
|
|
|
|
|
{Map<String, dynamic>? body,
|
|
|
|
|
Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
Function(String error, int statusCode)? onFailure,
|
|
|
|
|
bool isAllowAny = false,
|
|
|
|
|
bool isExternal = false}) async {
|
|
|
|
|
{Map<String, dynamic>? body, Function(dynamic response, int statusCode)? onSuccess, Function(String error, int statusCode)? onFailure, bool isAllowAny = false, bool isExternal = false}) async {
|
|
|
|
|
var token = await sharedPref.getString(PHARMACY_AUTORZIE_TOKEN);
|
|
|
|
|
var user = await sharedPref.getObject(USER_PROFILE);
|
|
|
|
|
String url;
|
|
|
|
|
@ -915,8 +760,7 @@ class BaseAppClient {
|
|
|
|
|
try {
|
|
|
|
|
if (isExternal) {
|
|
|
|
|
String token = await sharedPref.getString(TOKEN);
|
|
|
|
|
var languageID =
|
|
|
|
|
await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
var user = await sharedPref.getObject(USER_PROFILE);
|
|
|
|
|
if (body!.containsKey('SetupID')) {
|
|
|
|
|
body['SetupID'] = body.containsKey('SetupID')
|
|
|
|
|
@ -939,12 +783,11 @@ class BaseAppClient {
|
|
|
|
|
: user['OutSA'];
|
|
|
|
|
|
|
|
|
|
if (body.containsKey('isDentalAllowedBackend')) {
|
|
|
|
|
body['isDentalAllowedBackend'] =
|
|
|
|
|
body.containsKey('isDentalAllowedBackend')
|
|
|
|
|
? body['isDentalAllowedBackend'] != null
|
|
|
|
|
? body['isDentalAllowedBackend']
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND;
|
|
|
|
|
body['isDentalAllowedBackend'] = body.containsKey('isDentalAllowedBackend')
|
|
|
|
|
? body['isDentalAllowedBackend'] != null
|
|
|
|
|
? body['isDentalAllowedBackend']
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND
|
|
|
|
|
: IS_DENTAL_ALLOWED_BACKEND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body['DeviceTypeID'] = Platform.isAndroid ? 1 : 2;
|
|
|
|
|
@ -967,9 +810,7 @@ class BaseAppClient {
|
|
|
|
|
: user['PatientType'];
|
|
|
|
|
if (user != null) {
|
|
|
|
|
body['TokenID'] = token;
|
|
|
|
|
body['PatientID'] = body['PatientID'] != null
|
|
|
|
|
? body['PatientID']
|
|
|
|
|
: user['PatientID'];
|
|
|
|
|
body['PatientID'] = body['PatientID'] != null ? body['PatientID'] : user['PatientID'];
|
|
|
|
|
body['PatientOutSA'] = user['OutSA'];
|
|
|
|
|
// body['SessionID'] = SESSION_ID; //getSessionId(token);
|
|
|
|
|
}
|
|
|
|
|
@ -981,14 +822,11 @@ class BaseAppClient {
|
|
|
|
|
var ss = json.encode(body);
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection()) {
|
|
|
|
|
final response = await http
|
|
|
|
|
.post(Uri.parse(url.trim()), body: json.encode(body), headers: {
|
|
|
|
|
final response = await http.post(Uri.parse(url.trim()), body: json.encode(body), headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': token ?? '',
|
|
|
|
|
'Mobilenumber': user != null
|
|
|
|
|
? Utils.getPhoneNumberWithoutZero(user['MobileNumber'].toString())
|
|
|
|
|
: "",
|
|
|
|
|
'Mobilenumber': user != null ? Utils.getPhoneNumberWithoutZero(user['MobileNumber'].toString()) : "",
|
|
|
|
|
'Statictoken': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
|
|
|
|
|
'Username': user != null ? user['PatientID'].toString() : "",
|
|
|
|
|
});
|
|
|
|
|
@ -996,15 +834,8 @@ class BaseAppClient {
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400 || json == null) {
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['error']['ErrorEndUserMsgN'] ??
|
|
|
|
|
'Error While Fetching data',
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['error']['ErrorEndUserMsgN'] ??
|
|
|
|
|
'Error While Fetching data',
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!(parsed['error']['ErrorEndUserMsgN'] ?? 'Error While Fetching data', statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['error']['ErrorEndUserMsgN'] ?? 'Error While Fetching data', statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
// var parsed = json.decode(response.body.toString());
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
@ -1012,8 +843,7 @@ class BaseAppClient {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['ErrorType'] == 4) {
|
|
|
|
|
navigateToAppUpdate(
|
|
|
|
|
AppGlobal.context, parsed['ErrorEndUserMessage']);
|
|
|
|
|
navigateToAppUpdate(AppGlobal.context, parsed['ErrorEndUserMessage']);
|
|
|
|
|
}
|
|
|
|
|
if (isAllowAny) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
@ -1028,47 +858,25 @@ class BaseAppClient {
|
|
|
|
|
if (parsed != null) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 ||
|
|
|
|
|
parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 &&
|
|
|
|
|
parsed['IsAuthenticated']) {
|
|
|
|
|
if (parsed['message'] == null &&
|
|
|
|
|
parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) {
|
|
|
|
|
if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
if (parsed['ErrorSearchMsg'] == null) {
|
|
|
|
|
onFailure!("Server Error found with no available message",
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
"Server Error found with no available message",
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!("Server Error found with no available message", statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, "Server Error found with no available message", statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!(parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['message'] ??
|
|
|
|
|
parsed['ErrorEndUserMessage'] ??
|
|
|
|
|
parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['message'] ??
|
|
|
|
|
parsed['ErrorEndUserMessage'] ??
|
|
|
|
|
parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!(parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
} else if (!parsed['IsAuthenticated']) {
|
|
|
|
|
await logout();
|
|
|
|
|
@ -1079,18 +887,11 @@ class BaseAppClient {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['message'] != null) {
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint,
|
|
|
|
|
parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
onFailure!(parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
logApiEndpointError(
|
|
|
|
|
endPoint,
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode);
|
|
|
|
|
onFailure!(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -1098,8 +899,7 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print(e);
|
|
|
|
|
@ -1111,15 +911,11 @@ class BaseAppClient {
|
|
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
"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) {
|
|
|
|
|
simplePost(url, body: body, headers: {}, onSuccess: (dynamic stringResponse, int statusCode) {
|
|
|
|
|
if (statusCode == 200) {
|
|
|
|
|
var jsonResponse = json.decode(stringResponse);
|
|
|
|
|
token = jsonResponse['auth_token'];
|
|
|
|
|
|