|
|
|
|
@ -10,7 +10,6 @@ import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/appUpdatePage/app_update_page.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
|
|
|
|
|
@ -31,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 {
|
|
|
|
|
@ -102,7 +100,7 @@ class BaseAppClient {
|
|
|
|
|
? body['PatientOutSA']
|
|
|
|
|
: PATIENT_OUT_SA
|
|
|
|
|
: PATIENT_OUT_SA;
|
|
|
|
|
body['SessionID'] = SESSION_ID; //getSe
|
|
|
|
|
body['SessionID'] = getSessionId(body['TokenID']); //getSe
|
|
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
@ -162,8 +160,8 @@ class BaseAppClient {
|
|
|
|
|
// if (parsed != null) {
|
|
|
|
|
// onSuccess(parsed, statusCode);
|
|
|
|
|
// } else {
|
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
// logout();
|
|
|
|
|
onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode);
|
|
|
|
|
// logout();
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1 || parsed['SMSLoginRequired'] == true) {
|
|
|
|
|
@ -466,7 +464,8 @@ class BaseAppClient {
|
|
|
|
|
|
|
|
|
|
simplePost(
|
|
|
|
|
String fullUrl, {
|
|
|
|
|
Map<String, dynamic> body, Map<String, String> headers,
|
|
|
|
|
Map<String, dynamic> body,
|
|
|
|
|
Map<String, String> headers,
|
|
|
|
|
Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
|
Function(String error, int statusCode) onFailure,
|
|
|
|
|
}) async {
|
|
|
|
|
@ -483,8 +482,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);
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400 || json == null) {
|
|
|
|
|
onFailure('Error While Fetching data', statusCode);
|
|
|
|
|
@ -496,7 +494,8 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
simpleGet(String fullUrl, {Function(dynamic response, int statusCode) onSuccess, Function(String error, int statusCode) onFailure, Map<String, String> queryParams, Map<String, String> headers}) async {
|
|
|
|
|
simpleGet(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");
|
|
|
|
|
|
|
|
|
|
@ -516,8 +515,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);
|
|
|
|
|
@ -543,8 +541,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);
|
|
|
|
|
@ -556,7 +553,8 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
simpleDelete(String fullUrl, {Function(dynamic response, int statusCode) onSuccess, Function(String error, int statusCode) onFailure, Map<String, String> queryParams, Map<String, String> headers}) async {
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
@ -576,8 +574,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);
|
|
|
|
|
@ -589,13 +586,13 @@ class BaseAppClient {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> handleUnauthorized(int statusCode, {String forUrl}) async{
|
|
|
|
|
if(forUrl.startsWith(EXA_CART_API_BASE_URL) && statusCode == 401) {
|
|
|
|
|
final token = await generatePackagesToken();
|
|
|
|
|
packagesAuthHeader['Authorization'] = 'Bearer $token';
|
|
|
|
|
return token != null && (token is String);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
Future<bool> handleUnauthorized(int statusCode, {String forUrl}) async {
|
|
|
|
|
if (forUrl.startsWith(EXA_CART_API_BASE_URL) && statusCode == 401) {
|
|
|
|
|
final token = await generatePackagesToken();
|
|
|
|
|
packagesAuthHeader['Authorization'] = 'Bearer $token';
|
|
|
|
|
return token != null && (token is String);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logout() async {
|
|
|
|
|
@ -726,7 +723,7 @@ class BaseAppClient {
|
|
|
|
|
print("statusCode :$statusCode");
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400 || json == null) {
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
onFailure(parsed['error']['ErrorEndUserMsg'] ??'Error While Fetching data', statusCode);
|
|
|
|
|
onFailure(parsed['error']['ErrorEndUserMsg'] ?? 'Error While Fetching data', statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
// var parsed = json.decode(response.body.toString());
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
@ -791,15 +788,10 @@ 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();
|
|
|
|
|
|