From c1fbce7eae554a146b3d856df6396282774d2098 Mon Sep 17 00:00:00 2001 From: Sultan khan <> Date: Sun, 24 Dec 2023 11:05:52 +0300 Subject: [PATCH] bug fixes --- lib/analytics/flows/appointments.dart | 2 +- lib/config/config.dart | 6 +- lib/core/service/client/base_app_client.dart | 488 +++++++++++++----- .../widgets/DentalComplaintCard.dart | 2 +- lib/pages/login/login.dart | 81 ++- .../rate_appointment_doctor.dart | 9 +- .../authentication/auth_provider.dart | 170 +++--- .../clinic_services/get_clinic_service.dart | 2 +- 8 files changed, 525 insertions(+), 235 deletions(-) diff --git a/lib/analytics/flows/appointments.dart b/lib/analytics/flows/appointments.dart index d96421da..594c9179 100644 --- a/lib/analytics/flows/appointments.dart +++ b/lib/analytics/flows/appointments.dart @@ -64,7 +64,7 @@ class Appointment { logger('book_appointment_chief_complaints', parameters: { 'appointment_type': appointment_type, 'clinic_type': clinic!.clinicDescription, - 'hospital_name': hospital!.name, + 'hospital_name':hospital!=null ? hospital!.name :"", 'treatment_type': treatment.name, }); } diff --git a/lib/config/config.dart b/lib/config/config.dart index c731f951..61fd3d74 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -20,8 +20,8 @@ var PACKAGES_ORDERS = '/api/orders'; var PACKAGES_ORDER_HISTORY = '/api/orders/items'; var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara'; // var BASE_URL = 'http://10.50.100.198:2018/'; - var BASE_URL = 'https://uat.hmgwebservices.com/'; -// var BASE_URL = 'https://hmgwebservices.com/'; + // var BASE_URL = 'https://uat.hmgwebservices.com/'; +var BASE_URL = 'https://hmgwebservices.com/'; // var BASE_URL = 'https://orash.cloudsolutions.com.sa/'; // var BASE_URL = 'https://vidauat.cloudsolutions.com.sa/'; // var BASE_URL = 'https://vidamergeuat.cloudsolutions.com.sa/'; @@ -339,7 +339,7 @@ var UPDATE_COVID_QUESTIONNAIRE = 'Services/Doctors.svc/REST/COVID19_Questionnari var CHANNEL = 3; var GENERAL_ID = 'Cs2020@2016\$2958'; var IP_ADDRESS = '10.20.10.20'; -var VERSION_ID = 11.5; +var VERSION_ID = 11.6; var SETUP_ID = '91877'; var LANGUAGE = 2; // var PATIENT_OUT_SA = 0; diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index a6a69cbf..a1d6000f 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -30,16 +30,17 @@ AppSharedPreferences sharedPref = new AppSharedPreferences(); /// onFailure: (String error, int statusCode) {}, /// body: Map(); /// -AuthenticatedUserObject authenticatedUserObject = locator(); +AuthenticatedUserObject authenticatedUserObject = + locator(); VitalSignService _vitalSignService = locator(); class BaseAppClient { final _analytics = locator(); post(String endPoint, - {Map? body, - Function(dynamic response, int statusCode)? onSuccess, - Function(String error, int statusCode)? onFailure, + {required Map 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 headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}; + Map 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(AppGlobal.context, listen: false).isArabic ? 1 : 2; + body['LanguageID'] = + Provider.of(AppGlobal.context, listen: false) + .isArabic + ? 1 + : 2; } } else { // body['LanguageID'] = (languageID.toString().toLowerCase() == 'ar' ? 1 : 2); - body['LanguageID'] = Provider.of(AppGlobal.context, listen: false).isArabic ? 1 : 2; + body['LanguageID'] = + Provider.of(AppGlobal.context, listen: false) + .isArabic + ? 1 + : 2; } // body['LanguageID'] = Provider.of(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? body, Function(dynamic response, int statusCode)? onSuccess, Function(String error, int statusCode)? onFailure, bool isAllowAny = false, bool isExternal = false}) async { + {Map? 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 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? queryParams, Map? headers}) async { + {Function(dynamic response, int statusCode)? onSuccess, + Function(String error, int statusCode)? onFailure, + Map? queryParams, + Map? 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? body, Map? headers, Function(dynamic response, int statusCode)? onSuccess, Function(String error, int statusCode)? onFailure}) async { + simplePut(String fullUrl, + {Map? body, + Map? 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? queryParams, Map? headers}) async { + {Function(dynamic response, int statusCode)? onSuccess, + Function(String error, int statusCode)? onFailure, + Map? queryParams, + Map? 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 handleUnauthorized(int statusCode, {required String forUrl}) async { + Future 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(AppGlobal.context, listen: false).isLogin = false; - var model = Provider.of(AppGlobal.context, listen: false); + Provider.of(AppGlobal.context, listen: false).isLogin = + false; + var model = + Provider.of(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? body, Function(dynamic response, int statusCode)? onSuccess, Function(String error, int statusCode)? onFailure, bool isAllowAny = false, bool isExternal = false}) async { + {Map? 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 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']; diff --git a/lib/pages/BookAppointment/widgets/DentalComplaintCard.dart b/lib/pages/BookAppointment/widgets/DentalComplaintCard.dart index d65226a2..dbcdb5f7 100644 --- a/lib/pages/BookAppointment/widgets/DentalComplaintCard.dart +++ b/lib/pages/BookAppointment/widgets/DentalComplaintCard.dart @@ -10,7 +10,7 @@ import 'package:flutter/material.dart'; // ignore: must_be_immutable class DentalComplaintCard extends StatefulWidget { final ListDentalChiefComplain listDentalChiefComplain; - late VoidCallback logAnalytics; + late Function logAnalytics; var languageID; Function? onSelectedMethod; bool isDoctorNameSearch; diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 24e69a5c..1a4a02b5 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -51,10 +51,13 @@ class _Login extends State { final authService = AuthProvider(); var sharedPref = AppSharedPreferences(); bool isLoading = false; - AppointmentRateViewModel appointmentRateViewModel = locator(); - PharmacyModuleViewModel pharmacyModuleViewModel = locator(); + AppointmentRateViewModel appointmentRateViewModel = + locator(); + PharmacyModuleViewModel pharmacyModuleViewModel = + locator(); - AuthenticatedUserObject authenticatedUserObject = locator(); + AuthenticatedUserObject authenticatedUserObject = + locator(); late ProjectViewModel projectViewModel; late ToDoCountProviderModel toDoProvider; @@ -110,7 +113,9 @@ class _Login extends State { HabibLogoWidget(), SizedBox(height: 50), Text( - loginType == 1 ? TranslationBase.of(context).enterNationalId : TranslationBase.of(context).enterFile, + loginType == 1 + ? TranslationBase.of(context).enterNationalId + : TranslationBase.of(context).enterFile, style: TextStyle( fontSize: 16, fontWeight: FontWeight.w600, @@ -129,7 +134,9 @@ class _Login extends State { Directionality( textDirection: TextDirection.ltr, child: inputWidget( - loginType == 1 ? TranslationBase.of(context).nationalIdNumber : TranslationBase.of(context).medicalFileNumber, + loginType == 1 + ? TranslationBase.of(context).nationalIdNumber + : TranslationBase.of(context).medicalFileNumber, "Xxxxxxxxx", nationalIDorFile, ), @@ -143,8 +150,7 @@ class _Login extends State { DefaultButton( TranslationBase.of(context).login, () { - if (!isButtonDisabled) - this.startLogin(); + if (!isButtonDisabled) this.startLogin(); }, disabledColor: Color(0xff575757), ), @@ -153,7 +159,9 @@ class _Login extends State { ); } - Widget inputWidget(String _labelText, String _hintText, TextEditingController _controller, {String? prefix, bool isEnable = true, bool hasSelection = false}) { + Widget inputWidget( + String _labelText, String _hintText, TextEditingController _controller, + {String? prefix, bool isEnable = true, bool hasSelection = false}) { return Container( padding: EdgeInsets.only(left: 16, right: 16, bottom: 15, top: 15), alignment: Alignment.center, @@ -237,12 +245,13 @@ class _Login extends State { startLogin() { if (isButtonDisabled == false) { - checkUserAuthentication(); - } + checkUserAuthentication(); + } } void validateForm() { - if (util.validateIDBox(nationalIDorFile.text, loginType) == true && util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true) { + if (util.validateIDBox(nationalIDorFile.text, loginType) == true && + util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true) { setState(() { isButtonDisabled = false; }); @@ -306,7 +315,8 @@ class _Login extends State { }, cancelFunction: () => {}); dialog.showAlertDialog(context); - projectViewModel.analytics.loginRegistration.login_fail(error: err.toString()); + projectViewModel.analytics.loginRegistration + .login_fail(error: err.toString()); }); } @@ -348,7 +358,8 @@ class _Login extends State { projectViewModel.setPrivilege(privilegeList: result); result = CheckActivationCode.fromJson(result); result.list.isFamily = false; - this.sharedPref.setString(BLOOD_TYPE, result.patientBloodType != null ? result.patientBloodType : ""); + this.sharedPref.setString(BLOOD_TYPE, + result.patientBloodType != null ? result.patientBloodType : ""); this.sharedPref.setObject(USER_PROFILE, result.list); this.sharedPref.setObject(MAIN_USER, result.list); this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID); @@ -359,13 +370,16 @@ class _Login extends State { projectViewModel.isLogin = true; authenticatedUserObject.user = result.list; projectViewModel.user = authenticatedUserObject.user; - int languageID = Provider.of(context, listen: false).isArabic ? 1 : 2; + int languageID = + Provider.of(context, listen: false).isArabic + ? 1 + : 2; appointmentRateViewModel .getIsLastAppointmentRatedList(languageID) .then((value) => { checkIfIsInPatient(), getToDoCount(), - GifLoaderDialogUtils.hideDialog(context), + // GifLoaderDialogUtils.hideDialog(context), if (appointmentRateViewModel.isHaveAppointmentNotRate) { Navigator.pushAndRemoveUntil( @@ -396,22 +410,24 @@ class _Login extends State { toDoProvider.setState(0, true, toDoProvider.notificationsCount); ClinicListService service = new ClinicListService(); service.getActiveAppointmentNo(context).then((res) { - print(res['AppointmentActiveNumber']); + //print(res['AppointmentActiveNumber']); if (res['MessageStatus'] == 1) { - toDoProvider.setState(res['AppointmentActiveNumber'], true, toDoProvider.notificationsCount); + toDoProvider.setState(res['AppointmentActiveNumber'], true, + toDoProvider.notificationsCount); } else {} }).catchError((err) { print(err); }); } - checkIfIsInPatient() { + checkIfIsInPatient() async { bool isAdmitted = false; bool hasAdmissionRequest = false; GetAdmissionInfoResponseModel getAdmissionInfoResponseModel; GetAdmissionRequestInfoResponseModel getAdmissionRequestInfoResponseModel; ClinicListService? service = new ClinicListService(); - service.checkIfInPatientAPI(context).then((res) { + dynamic res = await service.checkIfInPatientAPI(context); + if (res != null) { if (res['MessageStatus'] == 1) { isAdmitted = res['isAdmitted']; hasAdmissionRequest = res['hasAdmissionRequests']; @@ -419,22 +435,30 @@ class _Login extends State { print("Has Admission Request: $hasAdmissionRequest"); if (isAdmitted) { if (res['PatientAdmittedInformation'].length != 0) { - getAdmissionInfoResponseModel = GetAdmissionInfoResponseModel.fromJson(res['PatientAdmittedInformation'][0]); - projectViewModel.setInPatientProjectID(res['PatientAdmittedInformation'][0]['ProjectID']); - projectViewModel.setInPatientAdmissionInfo(getAdmissionInfoResponseModel); + getAdmissionInfoResponseModel = + GetAdmissionInfoResponseModel.fromJson( + res['PatientAdmittedInformation'][0]); + projectViewModel.setInPatientProjectID( + res['PatientAdmittedInformation'][0]['ProjectID']); + projectViewModel + .setInPatientAdmissionInfo(getAdmissionInfoResponseModel); projectViewModel.setIsPatientAdmitted(true); } } if (hasAdmissionRequest) { if (res['MedicalInstruction'].length != 0) { - getAdmissionRequestInfoResponseModel = GetAdmissionRequestInfoResponseModel.fromJson(res['MedicalInstruction'][0]); - projectViewModel.setInPatientProjectID(res['MedicalInstruction'][0]['ProjectID']); - projectViewModel.setInPatientAdmissionRequest(getAdmissionRequestInfoResponseModel); + getAdmissionRequestInfoResponseModel = + GetAdmissionRequestInfoResponseModel.fromJson( + res['MedicalInstruction'][0]); + projectViewModel.setInPatientProjectID( + res['MedicalInstruction'][0]['ProjectID']); + projectViewModel.setInPatientAdmissionRequest( + getAdmissionRequestInfoResponseModel); projectViewModel.setPatientHasAdmissionRequest(true); } } - } else {} - }); + } + } } void registerGeoZones() async { @@ -448,7 +472,8 @@ class _Login extends State { if (registerData != null) { setState(() { - this.nationalIDorFile.text = registerData['PatientIdentificationID'].toString(); + this.nationalIDorFile.text = + registerData['PatientIdentificationID'].toString(); this.isButtonDisabled = false; this.loginType = 1; this.mobileNo = registerData['PatientMobileNumber'].toString(); diff --git a/lib/pages/rateAppointment/rate_appointment_doctor.dart b/lib/pages/rateAppointment/rate_appointment_doctor.dart index ff1d2e33..249b44da 100644 --- a/lib/pages/rateAppointment/rate_appointment_doctor.dart +++ b/lib/pages/rateAppointment/rate_appointment_doctor.dart @@ -201,11 +201,12 @@ class _RateAppointmentDoctorState extends State { ), ); } else { - Navigator.pop( + //changed due to blank page coming before + Navigator.pushReplacement( context, - // FadePage( - // page: LandingPage(), - // ), + FadePage( + page: LandingPage(), + ), ); } } diff --git a/lib/services/authentication/auth_provider.dart b/lib/services/authentication/auth_provider.dart index a473873a..48ef2368 100644 --- a/lib/services/authentication/auth_provider.dart +++ b/lib/services/authentication/auth_provider.dart @@ -33,35 +33,48 @@ enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED } AppSharedPreferences sharedPref = AppSharedPreferences(); AppGlobal appGlobal = AppGlobal(); -const String INSERT_DEVICE_IMEI = 'Services/Patients.svc/REST/Patient_INSERTDeviceIMEI'; -const String SELECT_DEVICE_IMEI = 'Services/Patients.svc/REST/Patient_SELECTDeviceIMEIbyIMEI'; -const String CHECK_PATIENT_AUTH = 'Services/Authentication.svc/REST/CheckPatientAuthentication'; +const String INSERT_DEVICE_IMEI = + 'Services/Patients.svc/REST/Patient_INSERTDeviceIMEI'; +const String SELECT_DEVICE_IMEI = + 'Services/Patients.svc/REST/Patient_SELECTDeviceIMEIbyIMEI'; +const String CHECK_PATIENT_AUTH = + 'Services/Authentication.svc/REST/CheckPatientAuthentication'; const GET_MOBILE_INFO = 'Services/Authentication.svc/REST/GetMobileLoginInfo'; -const SEND_ACTIVATION_CODE = 'Services/Authentication.svc/REST/SendActivationCodebyOTPNotificationType'; +const SEND_ACTIVATION_CODE = + 'Services/Authentication.svc/REST/SendActivationCodebyOTPNotificationType'; -const SEND_ACTIVATION_CODE_REGISTER = 'Services/Authentication.svc/REST/SendActivationCodebyOTPNotificationTypeForRegistration'; -const CHECK_ACTIVATION_CODE = 'Services/Authentication.svc/REST/CheckActivationCode'; -const CHECK_ACTIVATION_CODE_REGISTER = 'Services/Authentication.svc/REST/CheckActivationCodeForRegistration'; +const SEND_ACTIVATION_CODE_REGISTER = + 'Services/Authentication.svc/REST/SendActivationCodebyOTPNotificationTypeForRegistration'; +const CHECK_ACTIVATION_CODE = + 'Services/Authentication.svc/REST/CheckActivationCode'; +const CHECK_ACTIVATION_CODE_REGISTER = + 'Services/Authentication.svc/REST/CheckActivationCodeForRegistration'; -const FORGOT_PASSWORD = 'Services/Authentication.svc/REST/CheckActivationCodeForSendFileNo'; -const CHECK_PATIENT_FOR_REGISTRATION = "Services/Authentication.svc/REST/CheckPatientForRegisteration"; +const FORGOT_PASSWORD = + 'Services/Authentication.svc/REST/CheckActivationCodeForSendFileNo'; +const CHECK_PATIENT_FOR_REGISTRATION = + "Services/Authentication.svc/REST/CheckPatientForRegisteration"; const CHECK_USER_STATUS = "Services/NHIC.svc/REST/GetPatientInfo"; const REGISTER_USER = 'Services/Authentication.svc/REST/PatientRegistration'; -const LOGGED_IN_USER_URL = 'Services/MobileNotifications.svc/REST/Insert_PatientMobileDeviceInfo'; +const LOGGED_IN_USER_URL = + 'Services/MobileNotifications.svc/REST/Insert_PatientMobileDeviceInfo'; -const FORGOT_PATIENT_ID = 'Services/Authentication.svc/REST/SendPatientIDSMSByMobileNumber'; +const FORGOT_PATIENT_ID = + 'Services/Authentication.svc/REST/SendPatientIDSMSByMobileNumber'; const DASHBOARD = 'Services/Patients.svc/REST/PatientDashboard'; const PROFILE_SETTING = 'Services/Patients.svc/REST/GetPateintInfoForUpdate'; const SAVE_SETTING = 'Services/Patients.svc/REST/UpdatePateintInfo'; -const DEACTIVATE_ACCOUNT = 'Services/Patients.svc/REST/PatientAppleActivation_InsertUpdate'; +const DEACTIVATE_ACCOUNT = + 'Services/Patients.svc/REST/PatientAppleActivation_InsertUpdate'; class AuthProvider with ChangeNotifier { bool isLogin = false; bool isLoading = true; dynamic authenticatedUser; - AuthenticatedUserObject authenticatedUserObject = locator(); + AuthenticatedUserObject authenticatedUserObject = + locator(); var languageID; AuthProvider() { @@ -117,14 +130,17 @@ class AuthProvider with ChangeNotifier { var lastLogin = lstLogin; //await sharedPref.getInt( // LAST_LOGIN); //this.cs.sharedService.getStorage(AuthenticationService.LAST_LOGIN); //this.cs.sharedService.getSharedData(AuthenticationService.LAST_LOGIN, false); - var request = AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE)); + var request = + AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE)); var newRequest = INSERTDeviceIMEIRequest(); var imei = await sharedPref.getString(PUSH_TOKEN); // if (!request.) { newRequest.iMEI = imei; //imei!=null ? imei : ''; - newRequest.firstName = request.firstName ?? "" + " " + request.lastName! ?? ""; - newRequest.firstNameN = request.firstNameN ?? "" + " " + request.lastNameN! ?? ""; + newRequest.firstName = + request.firstName ?? "" + " " + request.lastName! ?? ""; + newRequest.firstNameN = + request.firstNameN ?? "" + " " + request.lastNameN! ?? ""; newRequest.lastNameN = request.lastNameN ?? ""; newRequest.outSA = request.outSA == 1 ? true : false; newRequest.biometricEnabled = false; @@ -139,7 +155,8 @@ class AuthProvider with ChangeNotifier { newRequest.tokenID = await sharedPref.getString(TOKEN); // } - await new BaseAppClient().post(INSERT_DEVICE_IMEI, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(INSERT_DEVICE_IMEI, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { throw error; @@ -157,37 +174,45 @@ class AuthProvider with ChangeNotifier { print(imei); Map request = {}; request['IMEI'] = imei; - await BaseAppClient().post(SELECT_DEVICE_IMEI, onSuccess: (dynamic response, int statusCode) async { + await BaseAppClient().post(SELECT_DEVICE_IMEI, + onSuccess: (dynamic response, int statusCode) async { localRes = Map(); if (response['Patient_SELECTDeviceIMEIbyIMEIList'][0] != null) { localRes = SelectDeviceIMEIRES.fromJson( response['Patient_SELECTDeviceIMEIbyIMEIList'][0]); } - request['LanguageID'] = Provider.of(AppGlobal.context, listen: false).isArabic ? 1 : 2; - await new BaseAppClient().post(SELECT_DEVICE_IMEI, onSuccess: (dynamic response, int statusCode) { - localRes = SelectDeviceIMEIRES.fromJson(response['Patient_SELECTDeviceIMEIbyIMEIList'][0]); - }, onFailure: (String error, int statusCode) { - throw error; - }, body: request); - return Future.value(localRes); - }); - } - catch (error) { + request['LanguageID'] = + Provider.of(AppGlobal.context, listen: false) + .isArabic + ? 1 + : 2; + await new BaseAppClient().post(SELECT_DEVICE_IMEI, + onSuccess: (dynamic response, int statusCode) { + localRes = SelectDeviceIMEIRES.fromJson( + response['Patient_SELECTDeviceIMEIbyIMEIList'][0]); + }, onFailure: (String error, int statusCode) { + throw error; + }, body: request); + return Future.value(localRes); + }, onFailure: (String error, int statusCode) {}, body: {}); + } catch (error) { return Future.error(error); } - } - Future checkPatientAuthentication(CheckPatientAuthenticationReq request) async { + Future checkPatientAuthentication( + CheckPatientAuthenticationReq request) async { request.versionID = VERSION_ID; request.channel = CHANNEL; request.iPAdress = IP_ADDRESS; request.generalid = GENERAL_ID; request.languageID = (languageID == 'ar' ? 1 : 2); - request.patientOutSA = (request.zipCode == '966' || request.zipCode == '+966') ? 0 : 1; + request.patientOutSA = + (request.zipCode == '966' || request.zipCode == '+966') ? 0 : 1; try { dynamic localRes; - await new BaseAppClient().post(CHECK_PATIENT_AUTH, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(CHECK_PATIENT_AUTH, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { throw error; @@ -211,7 +236,8 @@ class AuthProvider with ChangeNotifier { // request.patientTypeID = request.patientType; // request.patientType = request.patientType; dynamic localRes; - await new BaseAppClient().post(GET_MOBILE_INFO, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(GET_MOBILE_INFO, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { throw error; @@ -231,7 +257,8 @@ class AuthProvider with ChangeNotifier { request.isDentalAllowedBackend = false; dynamic localRes; - await new BaseAppClient().post(SEND_ACTIVATION_CODE, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(SEND_ACTIVATION_CODE, + onSuccess: (dynamic response, int statusCode) { localRes = response; authenticatedUser = CheckActivationCode.fromJson(localRes); }, onFailure: (String error, int statusCode) { @@ -251,7 +278,8 @@ class AuthProvider with ChangeNotifier { request.isDentalAllowedBackend = false; dynamic localRes; - await new BaseAppClient().post(SEND_ACTIVATION_CODE_REGISTER, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(SEND_ACTIVATION_CODE_REGISTER, + onSuccess: (dynamic response, int statusCode) { localRes = response; authenticatedUser = CheckActivationCode.fromJson(localRes); }, onFailure: (String error, int statusCode) { @@ -274,11 +302,13 @@ class AuthProvider with ChangeNotifier { neRequest.projectOutSA = neRequest.zipCode == '966' ? false : true; neRequest.isDentalAllowedBackend = false; // neRequest.deviceToken = null; - neRequest.forRegisteration = neRequest.isRegister != null ? neRequest.isRegister : false; + neRequest.forRegisteration = + neRequest.isRegister != null ? neRequest.isRegister : false; neRequest.isRegister = false; dynamic localRes; try { - await new BaseAppClient().post(CHECK_ACTIVATION_CODE, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(CHECK_ACTIVATION_CODE, + onSuccess: (dynamic response, int statusCode) { localRes = response; //CheckActivationCode.fromJson(); }, onFailure: (String error, int statusCode) { localRes = error; @@ -306,11 +336,13 @@ class AuthProvider with ChangeNotifier { neRequest.projectOutSA = neRequest.zipCode == '966' ? false : true; neRequest.isDentalAllowedBackend = false; // neRequest.deviceToken = null; - neRequest.forRegisteration = neRequest.isRegister != null ? neRequest.isRegister : false; + neRequest.forRegisteration = + neRequest.isRegister != null ? neRequest.isRegister : false; neRequest.isRegister = false; dynamic localRes; try { - await new BaseAppClient().post(CHECK_ACTIVATION_CODE_REGISTER, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(CHECK_ACTIVATION_CODE_REGISTER, + onSuccess: (dynamic response, int statusCode) { localRes = response; //CheckActivationCode.fromJson(); }, onFailure: (String error, int statusCode) { localRes = error; @@ -330,7 +362,8 @@ class AuthProvider with ChangeNotifier { return authenticatedUser; } - Future checkPatientForRegisteration(CheckPatientForRegistration request) async { + Future checkPatientForRegisteration( + CheckPatientForRegistration request) async { request.versionID = VERSION_ID; request.channel = CHANNEL; request.iPAdress = IP_ADDRESS; @@ -341,7 +374,8 @@ class AuthProvider with ChangeNotifier { // request.tokenID = ''; dynamic localRes; try { - await new BaseAppClient().post(CHECK_PATIENT_FOR_REGISTRATION, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(CHECK_PATIENT_FOR_REGISTRATION, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { localRes = error; @@ -364,7 +398,8 @@ class AuthProvider with ChangeNotifier { // request.tokenID = ''; dynamic localRes; try { - await new BaseAppClient().post(CHECK_USER_STATUS, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(CHECK_USER_STATUS, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { localRes = error; @@ -390,7 +425,9 @@ class AuthProvider with ChangeNotifier { final DateFormat dateFormat = DateFormat('MM/dd/yyyy'); final DateFormat dateFormat2 = DateFormat('dd/MM/yyyy'); if (nhic != null) { - requestN.dob = nhic['IsHijri'] ? nhic['DateOfBirth'] : dateFormat2.format(dateFormat.parse(nhic['DateOfBirth'])); + requestN.dob = nhic['IsHijri'] + ? nhic['DateOfBirth'] + : dateFormat2.format(dateFormat.parse(nhic['DateOfBirth'])); requestN.isHijri = nhic['IsHijri'] ? 1 : 0; requestN.healthId = requestN.patientobject!.eHealthIDField!; } @@ -401,7 +438,8 @@ class AuthProvider with ChangeNotifier { dynamic localRes; try { - await new BaseAppClient().post(REGISTER_USER, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(REGISTER_USER, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { localRes = error; @@ -413,17 +451,23 @@ class AuthProvider with ChangeNotifier { } } - Future registeredAuthenticatedUser(AuthenticatedUser user, deviceToken, lat, long) async { + Future registeredAuthenticatedUser( + AuthenticatedUser user, deviceToken, lat, long) async { var request = new RegisteredAuthenticatedUserRequest(); request.deviceToken = deviceToken; - request.voipToken = ""; //this.cs.sharedService.getSharedData(AuthenticationService.APNS_TOKEN, false); + request.voipToken = + ""; //this.cs.sharedService.getSharedData(AuthenticationService.APNS_TOKEN, false); request.deviceType = Platform.isIOS ? "1" : "2"; - request.patientMobileNumber = user.mobileNumber![0] == '0' ? user.mobileNumber : '0' + user.mobileNumber!; + request.patientMobileNumber = user.mobileNumber![0] == '0' + ? user.mobileNumber + : '0' + user.mobileNumber!; request.nationalID = user.patientIdentificationNo; request.gender = user.gender; request.patientID = user.patientID; request.patientOutSA = user.outSA; - request.loginType = await sharedPref.getInt(LAST_LOGIN) != null ? await sharedPref.getInt(LAST_LOGIN) : 1; + request.loginType = await sharedPref.getInt(LAST_LOGIN) != null + ? await sharedPref.getInt(LAST_LOGIN) + : 1; request.mACAddress = '00:00:00:00:00:00'; request.latitude = lat; request.longitude = long; @@ -432,7 +476,8 @@ class AuthProvider with ChangeNotifier { request.patientType = user.patientType; dynamic localRes; try { - await new BaseAppClient().post(LOGGED_IN_USER_URL, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(LOGGED_IN_USER_URL, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { localRes = error; @@ -458,7 +503,8 @@ class AuthProvider with ChangeNotifier { dynamic localRes; - await new BaseAppClient().post(FORGOT_PATIENT_ID, onSuccess: (response, statusCode) async { + await new BaseAppClient().post(FORGOT_PATIENT_ID, + onSuccess: (response, statusCode) async { localRes = response; }, onFailure: (String error, int statusCode) { throw error; @@ -476,7 +522,8 @@ class AuthProvider with ChangeNotifier { dynamic localRes; try { - await new BaseAppClient().post(FORGOT_PASSWORD, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(FORGOT_PASSWORD, + onSuccess: (dynamic response, int statusCode) { localRes = response; //CheckActivationCode.fromJson(); }, onFailure: (String error, int statusCode) { localRes = error; @@ -495,7 +542,8 @@ class AuthProvider with ChangeNotifier { dynamic localRes; try { - await new BaseAppClient().post(DASHBOARD, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(DASHBOARD, + onSuccess: (dynamic response, int statusCode) { localRes = response; //CheckActivationCode.fromJson(); }, onFailure: (String error, int statusCode) { localRes = error; @@ -512,7 +560,8 @@ class AuthProvider with ChangeNotifier { getSettings() async { dynamic localRes; try { - await new BaseAppClient().post(PROFILE_SETTING, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(PROFILE_SETTING, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { localRes = error; @@ -527,7 +576,8 @@ class AuthProvider with ChangeNotifier { Future saveSettings(request) async { dynamic localRes; try { - await new BaseAppClient().post(SAVE_SETTING, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(SAVE_SETTING, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { localRes = error; @@ -542,7 +592,8 @@ class AuthProvider with ChangeNotifier { Future deactivateAccount(request, bool isLogin) async { dynamic localRes; try { - await new BaseAppClient().post(DEACTIVATE_ACCOUNT, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(DEACTIVATE_ACCOUNT, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { localRes = error; @@ -558,7 +609,8 @@ class AuthProvider with ChangeNotifier { Future activateAccount(request) async { dynamic localRes; try { - await new BaseAppClient().post(DEACTIVATE_ACCOUNT, onSuccess: (dynamic response, int statusCode) { + await new BaseAppClient().post(DEACTIVATE_ACCOUNT, + onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { localRes = error; @@ -575,8 +627,10 @@ class AuthProvider with ChangeNotifier { await sharedPref.remove(LOGIN_TOKEN_ID); await sharedPref.remove(PHARMACY_CUSTOMER_ID); await authenticatedUserObject.getUser(); - Provider.of(AppGlobal.context, listen: false).isLogin = false; - var model = Provider.of(AppGlobal.context, listen: false); + Provider.of(AppGlobal.context, listen: false).isLogin = + false; + var model = + Provider.of(AppGlobal.context, listen: false); model.setState(0, false, ""); Navigator.of(AppGlobal.context).pushReplacementNamed(HOME); } diff --git a/lib/services/clinic_services/get_clinic_service.dart b/lib/services/clinic_services/get_clinic_service.dart index 1de5e6ab..e9a2319f 100644 --- a/lib/services/clinic_services/get_clinic_service.dart +++ b/lib/services/clinic_services/get_clinic_service.dart @@ -52,7 +52,7 @@ class ClinicListService extends BaseService { } Future checkIfInPatientAPI(context) async { - Map request; + Map? request; request = { "IsActiveAppointment": false, };