|
|
|
|
@ -30,16 +30,17 @@ 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 {
|
|
|
|
|
final _analytics = locator<GAnalytics>();
|
|
|
|
|
|
|
|
|
|
post(String endPoint,
|
|
|
|
|
{Map<String, dynamic>? body,
|
|
|
|
|
Function(dynamic response, int statusCode)? onSuccess,
|
|
|
|
|
Function(String error, int statusCode)? onFailure,
|
|
|
|
|
{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,
|
|
|
|
|
@ -54,16 +55,21 @@ class BaseAppClient {
|
|
|
|
|
url = BASE_URL + endPoint;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
var 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) {
|
|
|
|
|
var token = await sharedPref.getString(TOKEN);
|
|
|
|
|
var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
String? token = await sharedPref.getString(TOKEN);
|
|
|
|
|
String? languageID =
|
|
|
|
|
await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');
|
|
|
|
|
if (endPoint == SEND_ACTIVATION_CODE) {
|
|
|
|
|
languageID = 'en';
|
|
|
|
|
}
|
|
|
|
|
if (body!.containsKey('SetupID')) {
|
|
|
|
|
if (body.containsKey('SetupID')) {
|
|
|
|
|
body['SetupID'] = body.containsKey('SetupID')
|
|
|
|
|
? body['SetupID'] != null
|
|
|
|
|
? body['SetupID']
|
|
|
|
|
@ -75,14 +81,22 @@ class BaseAppClient {
|
|
|
|
|
body['Channel'] = CHANNEL;
|
|
|
|
|
|
|
|
|
|
if (body.containsKey('LanguageID')) {
|
|
|
|
|
if(body['LanguageID'] != null) {
|
|
|
|
|
if (body['LanguageID'] != null) {
|
|
|
|
|
body['LanguageID'] = 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;
|
|
|
|
|
@ -91,18 +105,19 @@ class BaseAppClient {
|
|
|
|
|
body['generalid'] = GENERAL_ID;
|
|
|
|
|
// body['isVidaPlus'] = true;
|
|
|
|
|
|
|
|
|
|
double? lat = await AppSharedPreferences().getDouble(USER_LAT);
|
|
|
|
|
double? long = await AppSharedPreferences().getDouble(USER_LONG);
|
|
|
|
|
double lat = await AppSharedPreferences().getDouble(USER_LAT) ?? 0.0;
|
|
|
|
|
double long = await AppSharedPreferences().getDouble(USER_LONG) ?? 0.0;
|
|
|
|
|
|
|
|
|
|
body['Latitude'] = lat == null ? 0.0 : lat;
|
|
|
|
|
body['Longitude'] = long == null ? 0.0 : long;
|
|
|
|
|
body['Latitude'] = lat;
|
|
|
|
|
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
|
|
|
|
|
@ -146,7 +161,9 @@ 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
|
|
|
|
|
@ -176,20 +193,23 @@ class BaseAppClient {
|
|
|
|
|
// Mobile no.: 0502303285
|
|
|
|
|
// ID: 119116817
|
|
|
|
|
|
|
|
|
|
body!.removeWhere((key, value) => key == null || value == null);
|
|
|
|
|
body.removeWhere((key, value) => key == null || value == null);
|
|
|
|
|
|
|
|
|
|
// if (AppGlobal.isNetworkDebugEnabled) {
|
|
|
|
|
print("URL : $url");
|
|
|
|
|
final jsonBody = json.encode(body);
|
|
|
|
|
print(jsonBody);
|
|
|
|
|
print("URL : $url");
|
|
|
|
|
final jsonBody = json.encode(body);
|
|
|
|
|
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);
|
|
|
|
|
onFailure('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));
|
|
|
|
|
@ -197,54 +217,76 @@ class BaseAppClient {
|
|
|
|
|
// print("Response: $parsed");
|
|
|
|
|
|
|
|
|
|
if (isAllowAny) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
if (parsed['Response_Message'] != null) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
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();
|
|
|
|
|
logApiEndpointError(endPoint, "session logged out", statusCode);
|
|
|
|
|
}
|
|
|
|
|
if (isAllowAny) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else if (parsed['IsAuthenticated'] == null) {
|
|
|
|
|
if (parsed['isSMSSent'] == true) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else if (parsed['Result'] == 'OK') {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
// 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) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) {
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 ||
|
|
|
|
|
parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
} else if (parsed['MessageStatus'] == 2 &&
|
|
|
|
|
parsed['IsAuthenticated']) {
|
|
|
|
|
if (parsed['SameClinicApptList'] != null) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
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);
|
|
|
|
|
onFailure(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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -253,14 +295,21 @@ class BaseAppClient {
|
|
|
|
|
// }
|
|
|
|
|
else {
|
|
|
|
|
if (parsed['SameClinicApptList'] != null) {
|
|
|
|
|
onSuccess!(parsed, statusCode);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -268,18 +317,23 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure!('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
onFailure('Please Check The Internet Connection', -1);
|
|
|
|
|
_analytics.errorTracking
|
|
|
|
|
.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print(e);
|
|
|
|
|
onFailure!(e.toString(), -1);
|
|
|
|
|
onFailure(e.toString(), -1);
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "api exception: $e");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
@ -296,13 +350,16 @@ 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')
|
|
|
|
|
@ -364,12 +421,14 @@ 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));
|
|
|
|
|
@ -377,8 +436,12 @@ 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);
|
|
|
|
|
@ -393,29 +456,56 @@ 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']) {
|
|
|
|
|
@ -427,11 +517,22 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -439,7 +540,8 @@ 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);
|
|
|
|
|
@ -451,7 +553,8 @@ 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,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@ -482,7 +585,10 @@ 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");
|
|
|
|
|
@ -496,7 +602,8 @@ 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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -528,7 +635,9 @@ 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",
|
|
|
|
|
@ -538,14 +647,19 @@ 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());
|
|
|
|
|
@ -554,7 +668,8 @@ 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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -570,7 +685,8 @@ 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),
|
|
|
|
|
@ -578,7 +694,12 @@ 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());
|
|
|
|
|
|
|
|
|
|
@ -590,12 +711,16 @@ 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;
|
|
|
|
|
|
|
|
|
|
@ -607,7 +732,8 @@ 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,
|
|
|
|
|
@ -615,7 +741,12 @@ 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);
|
|
|
|
|
@ -625,16 +756,22 @@ 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 {
|
|
|
|
|
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'});
|
|
|
|
|
headers!.addAll(
|
|
|
|
|
{'Content-Type': 'application/json', 'Accept': 'application/json'});
|
|
|
|
|
final response = await http.put(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
body: json.encode(body),
|
|
|
|
|
@ -643,7 +780,12 @@ 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);
|
|
|
|
|
@ -653,12 +795,16 @@ 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");
|
|
|
|
|
|
|
|
|
|
@ -670,7 +816,8 @@ 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,
|
|
|
|
|
@ -678,7 +825,12 @@ 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);
|
|
|
|
|
@ -688,11 +840,13 @@ 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';
|
|
|
|
|
@ -705,8 +859,10 @@ 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, false, "");
|
|
|
|
|
@ -720,7 +876,8 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
@ -740,7 +897,11 @@ 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;
|
|
|
|
|
@ -752,7 +913,8 @@ 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')
|
|
|
|
|
@ -775,11 +937,12 @@ 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;
|
|
|
|
|
@ -802,7 +965,9 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
@ -814,11 +979,14 @@ 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() : "",
|
|
|
|
|
});
|
|
|
|
|
@ -826,8 +994,15 @@ 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));
|
|
|
|
|
@ -835,7 +1010,8 @@ 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);
|
|
|
|
|
@ -850,25 +1026,47 @@ 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();
|
|
|
|
|
@ -879,11 +1077,18 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -891,7 +1096,8 @@ 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);
|
|
|
|
|
@ -903,11 +1109,15 @@ 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'];
|
|
|
|
|
|