@ -29,8 +29,7 @@ AppSharedPreferences sharedPref = new AppSharedPreferences();
/ / / onFailure: ( String error , int statusCode ) { } ,
/ / / onFailure: ( String error , int statusCode ) { } ,
/ / / body: Map ( ) ;
/ / / body: Map ( ) ;
/ / /
/ / /
AuthenticatedUserObject authenticatedUserObject =
AuthenticatedUserObject authenticatedUserObject = locator < AuthenticatedUserObject > ( ) ;
locator < AuthenticatedUserObject > ( ) ;
VitalSignService _vitalSignService = locator < VitalSignService > ( ) ;
VitalSignService _vitalSignService = locator < VitalSignService > ( ) ;
class BaseAppClient {
class BaseAppClient {
@ -50,14 +49,10 @@ class BaseAppClient {
/ / Map profile = await sharedPref . getObj ( DOCTOR_PROFILE ) ;
/ / Map profile = await sharedPref . getObj ( DOCTOR_PROFILE ) ;
var pharmacyToken = await sharedPref . getString ( PHARMACY_AUTORZIE_TOKEN ) ;
var pharmacyToken = await sharedPref . getString ( PHARMACY_AUTORZIE_TOKEN ) ;
var user = await sharedPref . getObject ( USER_PROFILE ) ;
var user = await sharedPref . getObject ( USER_PROFILE ) ;
Map < String , String > headers = {
Map < String , String > headers = { ' Content-Type ' : ' application/json ' , ' Accept ' : ' application/json ' } ;
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json '
} ;
if ( ! isExternal ) {
if ( ! isExternal ) {
String token = await sharedPref . getString ( TOKEN ) ;
String token = await sharedPref . getString ( TOKEN ) ;
var languageID =
var languageID = await sharedPref . getStringWithDefaultValue ( APP_LANGUAGE , ' ar ' ) ;
await sharedPref . getStringWithDefaultValue ( APP_LANGUAGE , ' ar ' ) ;
if ( body . containsKey ( ' SetupID ' ) ) {
if ( body . containsKey ( ' SetupID ' ) ) {
body [ ' SetupID ' ] = body . containsKey ( ' SetupID ' )
body [ ' SetupID ' ] = body . containsKey ( ' SetupID ' )
? body [ ' SetupID ' ] ! = null
? body [ ' SetupID ' ] ! = null
@ -72,15 +67,9 @@ class BaseAppClient {
body [ ' IPAdress ' ] = IP_ADDRESS ;
body [ ' IPAdress ' ] = IP_ADDRESS ;
body [ ' generalid ' ] = GENERAL_ID ;
body [ ' generalid ' ] = GENERAL_ID ;
body [ ' PatientOutSA ' ] = body . containsKey ( ' PatientOutSA ' )
? body [ ' PatientOutSA ' ] ! = null
? body [ ' PatientOutSA ' ]
: PATIENT_OUT_SA
: PATIENT_OUT_SA ;
if ( body . containsKey ( ' isDentalAllowedBackend ' ) ) {
if ( body . containsKey ( ' isDentalAllowedBackend ' ) ) {
body [ ' isDentalAllowedBackend ' ] =
body [ ' isDentalAllowedBackend ' ] = body . containsKey ( ' isDentalAllowedBackend ' )
body . containsKey ( ' isDentalAllowedBackend ' )
? body [ ' isDentalAllowedBackend ' ] ! = null
? body [ ' isDentalAllowedBackend ' ] ! = null
? body [ ' isDentalAllowedBackend ' ]
? body [ ' isDentalAllowedBackend ' ]
: IS_DENTAL_ALLOWED_BACKEND
: IS_DENTAL_ALLOWED_BACKEND
@ -107,19 +96,20 @@ class BaseAppClient {
: PATIENT_TYPE_ID ;
: PATIENT_TYPE_ID ;
if ( user ! = null ) {
if ( user ! = null ) {
body [ ' TokenID ' ] = token ;
body [ ' TokenID ' ] = token ;
body [ ' PatientID ' ] = body [ ' PatientID ' ] ! = null
body [ ' PatientID ' ] = body [ ' PatientID ' ] ! = null ? body [ ' PatientID ' ] : user [ ' PatientID ' ] ;
? body [ ' PatientID ' ]
: user [ ' PatientID ' ] ;
body [ ' PatientOutSA ' ] = user [ ' OutSA ' ] ;
body [ ' PatientOutSA ' ] = user [ ' OutSA ' ] ;
body [ ' PatientOutSA ' ] = body . containsKey ( ' PatientOutSA ' )
? body [ ' PatientOutSA ' ] ! = null
? body [ ' PatientOutSA ' ]
: PATIENT_OUT_SA
: PATIENT_OUT_SA ;
body [ ' SessionID ' ] = SESSION_ID ; / / getSe
body [ ' SessionID ' ] = SESSION_ID ; / / getSe
headers = {
headers = {
' Content-Type ' : ' application/json ' ,
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json ' ,
' Accept ' : ' application/json ' ,
' Authorization ' : pharmacyToken ,
' Authorization ' : pharmacyToken ,
' Mobilenumber ' : user ! = null
' Mobilenumber ' : user ! = null ? Utils . getPhoneNumberWithoutZero ( user [ ' MobileNumber ' ] . toString ( ) ) : " " ,
? Utils . getPhoneNumberWithoutZero (
user [ ' MobileNumber ' ] . toString ( ) )
: " " ,
' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Username ' : user [ ' PatientID ' ] . toString ( ) ,
' Username ' : user [ ' PatientID ' ] . toString ( ) ,
} ;
} ;
@ -131,8 +121,7 @@ class BaseAppClient {
print ( " Body : ${ json . encode ( body ) } " ) ;
print ( " Body : ${ json . encode ( body ) } " ) ;
if ( await Utils . checkConnection ( ) ) {
if ( await Utils . checkConnection ( ) ) {
final response = await http . post ( url . trim ( ) ,
final response = await http . post ( url . trim ( ) , body: json . encode ( body ) , headers: headers ) ;
body: json . encode ( body ) , headers: headers ) ;
final int statusCode = response . statusCode ;
final int statusCode = response . statusCode ;
print ( " statusCode : $ statusCode " ) ;
print ( " statusCode : $ statusCode " ) ;
if ( statusCode < 200 | | statusCode > = 400 | | json = = null ) {
if ( statusCode < 200 | | statusCode > = 400 | | json = = null ) {
@ -144,8 +133,7 @@ class BaseAppClient {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else {
} else {
if ( parsed [ ' ErrorType ' ] = = 4 ) {
if ( parsed [ ' ErrorType ' ] = = 4 ) {
navigateToAppUpdate (
navigateToAppUpdate ( AppGlobal . context , parsed [ ' ErrorEndUserMessage ' ] ) ;
AppGlobal . context , parsed [ ' ErrorEndUserMessage ' ] ) ;
}
}
if ( isAllowAny ) {
if ( isAllowAny ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
@ -160,35 +148,24 @@ class BaseAppClient {
if ( parsed ! = null ) {
if ( parsed ! = null ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else {
} else {
onFailure (
onFailure ( parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
logout ( ) ;
logout ( ) ;
}
}
}
}
} else if ( parsed [ ' MessageStatus ' ] = = 1 | |
} else if ( parsed [ ' MessageStatus ' ] = = 1 | | parsed [ ' SMSLoginRequired ' ] = = true ) {
parsed [ ' SMSLoginRequired ' ] = = true ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
debugPrint ( parsed . toString ( ) ) ;
} else if ( parsed [ ' MessageStatus ' ] = = 2 & & parsed [ ' IsAuthenticated ' ] ) {
} else if ( parsed [ ' MessageStatus ' ] = = 2 & &
parsed [ ' IsAuthenticated ' ] ) {
if ( parsed [ ' SameClinicApptList ' ] ! = null ) {
if ( parsed [ ' SameClinicApptList ' ] ! = null ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else {
} else {
if ( parsed [ ' message ' ] = = null & &
if ( parsed [ ' message ' ] = = null & & parsed [ ' ErrorEndUserMessage ' ] = = null ) {
parsed [ ' ErrorEndUserMessage ' ] = = null ) {
if ( parsed [ ' ErrorSearchMsg ' ] = = null ) {
if ( parsed [ ' ErrorSearchMsg ' ] = = null ) {
onFailure ( " Server Error found with no available message " ,
onFailure ( " Server Error found with no available message " , statusCode ) ;
statusCode ) ;
} else {
} else {
onFailure ( parsed [ ' ErrorSearchMsg ' ] , statusCode ) ;
onFailure ( parsed [ ' ErrorSearchMsg ' ] , statusCode ) ;
}
}
} else {
} else {
onFailure (
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' message ' ] ? ?
parsed [ ' ErrorEndUserMessage ' ] ? ?
parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
}
}
}
}
} else if ( ! parsed [ ' IsAuthenticated ' ] ) {
} else if ( ! parsed [ ' IsAuthenticated ' ] ) {
@ -202,9 +179,7 @@ class BaseAppClient {
if ( parsed [ ' message ' ] ! = null ) {
if ( parsed [ ' message ' ] ! = null ) {
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' message ' ] , statusCode ) ;
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' message ' ] , statusCode ) ;
} else {
} else {
onFailure (
onFailure ( parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
}
}
}
}
}
}
@ -241,16 +216,13 @@ class BaseAppClient {
' Content-Type ' : ' application/json ' ,
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json ' ,
' Accept ' : ' application/json ' ,
' Authorization ' : token ? ? ' ' ,
' Authorization ' : token ? ? ' ' ,
' Mobilenumber ' : user ! = null
' Mobilenumber ' : user ! = null ? Utils . getPhoneNumberWithoutZero ( user [ ' MobileNumber ' ] . toString ( ) ) : " " ,
? Utils . getPhoneNumberWithoutZero ( user [ ' MobileNumber ' ] . toString ( ) )
: " " ,
' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Username ' : user ! = null ? user [ ' PatientID ' ] . toString ( ) : " " ,
' Username ' : user ! = null ? user [ ' PatientID ' ] . toString ( ) : " " ,
} ;
} ;
if ( ! isExternal ) {
if ( ! isExternal ) {
String token = await sharedPref . getString ( TOKEN ) ;
String token = await sharedPref . getString ( TOKEN ) ;
var languageID =
var languageID = await sharedPref . getStringWithDefaultValue ( APP_LANGUAGE , ' ar ' ) ;
await sharedPref . getStringWithDefaultValue ( APP_LANGUAGE , ' ar ' ) ;
if ( body . containsKey ( ' SetupID ' ) ) {
if ( body . containsKey ( ' SetupID ' ) ) {
body [ ' SetupID ' ] = body . containsKey ( ' SetupID ' )
body [ ' SetupID ' ] = body . containsKey ( ' SetupID ' )
? body [ ' SetupID ' ] ! = null
? body [ ' SetupID ' ] ! = null
@ -272,8 +244,7 @@ class BaseAppClient {
: PATIENT_OUT_SA ;
: PATIENT_OUT_SA ;
if ( body . containsKey ( ' isDentalAllowedBackend ' ) ) {
if ( body . containsKey ( ' isDentalAllowedBackend ' ) ) {
body [ ' isDentalAllowedBackend ' ] =
body [ ' isDentalAllowedBackend ' ] = body . containsKey ( ' isDentalAllowedBackend ' )
body . containsKey ( ' isDentalAllowedBackend ' )
? body [ ' isDentalAllowedBackend ' ] ! = null
? body [ ' isDentalAllowedBackend ' ] ! = null
? body [ ' isDentalAllowedBackend ' ]
? body [ ' isDentalAllowedBackend ' ]
: IS_DENTAL_ALLOWED_BACKEND
: IS_DENTAL_ALLOWED_BACKEND
@ -300,9 +271,7 @@ class BaseAppClient {
: PATIENT_TYPE_ID ;
: PATIENT_TYPE_ID ;
if ( user ! = null ) {
if ( user ! = null ) {
body [ ' TokenID ' ] = token ;
body [ ' TokenID ' ] = token ;
body [ ' PatientID ' ] = body [ ' PatientID ' ] ! = null
body [ ' PatientID ' ] = body [ ' PatientID ' ] ! = null ? body [ ' PatientID ' ] : user [ ' PatientID ' ] ;
? body [ ' PatientID ' ]
: user [ ' PatientID ' ] ;
body [ ' PatientOutSA ' ] = user [ ' OutSA ' ] ;
body [ ' PatientOutSA ' ] = user [ ' OutSA ' ] ;
body [ ' SessionID ' ] = SESSION_ID ; / / getSe
body [ ' SessionID ' ] = SESSION_ID ; / / getSe
headers = {
headers = {
@ -321,8 +290,7 @@ class BaseAppClient {
print ( " Body : ${ json . encode ( body ) } " ) ;
print ( " Body : ${ json . encode ( body ) } " ) ;
if ( await Utils . checkConnection ( ) ) {
if ( await Utils . checkConnection ( ) ) {
final response = await http . post ( url . trim ( ) ,
final response = await http . post ( url . trim ( ) , body: json . encode ( body ) , headers: headers ) ;
body: json . encode ( body ) , headers: headers ) ;
final int statusCode = response . statusCode ;
final int statusCode = response . statusCode ;
print ( " statusCode : $ statusCode " ) ;
print ( " statusCode : $ statusCode " ) ;
if ( statusCode < 200 | | statusCode > = 400 | | json = = null ) {
if ( statusCode < 200 | | statusCode > = 400 | | json = = null ) {
@ -334,8 +302,7 @@ class BaseAppClient {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else {
} else {
if ( parsed [ ' ErrorType ' ] = = 4 ) {
if ( parsed [ ' ErrorType ' ] = = 4 ) {
navigateToAppUpdate (
navigateToAppUpdate ( AppGlobal . context , parsed [ ' ErrorEndUserMessage ' ] ) ;
AppGlobal . context , parsed [ ' ErrorEndUserMessage ' ] ) ;
}
}
if ( isAllowAny ) {
if ( isAllowAny ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
@ -350,34 +317,24 @@ class BaseAppClient {
if ( parsed ! = null ) {
if ( parsed ! = null ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else {
} else {
onFailure (
onFailure ( parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
logout ( ) ;
logout ( ) ;
}
}
}
}
} else if ( parsed [ ' MessageStatus ' ] = = 1 | |
} else if ( parsed [ ' MessageStatus ' ] = = 1 | | parsed [ ' SMSLoginRequired ' ] = = true ) {
parsed [ ' SMSLoginRequired ' ] = = true ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else if ( parsed [ ' MessageStatus ' ] = = 2 & &
} else if ( parsed [ ' MessageStatus ' ] = = 2 & & parsed [ ' IsAuthenticated ' ] ) {
parsed [ ' IsAuthenticated ' ] ) {
if ( parsed [ ' SameClinicApptList ' ] ! = null ) {
if ( parsed [ ' SameClinicApptList ' ] ! = null ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else {
} else {
if ( parsed [ ' message ' ] = = null & &
if ( parsed [ ' message ' ] = = null & & parsed [ ' ErrorEndUserMessage ' ] = = null ) {
parsed [ ' ErrorEndUserMessage ' ] = = null ) {
if ( parsed [ ' ErrorSearchMsg ' ] = = null ) {
if ( parsed [ ' ErrorSearchMsg ' ] = = null ) {
onFailure ( " Server Error found with no available message " ,
onFailure ( " Server Error found with no available message " , statusCode ) ;
statusCode ) ;
} else {
} else {
onFailure ( parsed [ ' ErrorSearchMsg ' ] , statusCode ) ;
onFailure ( parsed [ ' ErrorSearchMsg ' ] , statusCode ) ;
}
}
} else {
} else {
onFailure (
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' message ' ] ? ?
parsed [ ' ErrorEndUserMessage ' ] ? ?
parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
}
}
}
}
} else if ( ! parsed [ ' IsAuthenticated ' ] ) {
} else if ( ! parsed [ ' IsAuthenticated ' ] ) {
@ -391,9 +348,7 @@ class BaseAppClient {
if ( parsed [ ' message ' ] ! = null ) {
if ( parsed [ ' message ' ] ! = null ) {
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' message ' ] , statusCode ) ;
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' message ' ] , statusCode ) ;
} else {
} else {
onFailure (
onFailure ( parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
}
}
}
}
}
}
@ -409,8 +364,7 @@ class BaseAppClient {
}
}
Future navigateToAppUpdate ( context , String text ) async {
Future navigateToAppUpdate ( context , String text ) async {
Navigator . pushReplacement (
Navigator . pushReplacement ( context , FadePage ( page: AppUpdatePage ( appUpdateText: text ) ) ) ;
context , FadePage ( page: AppUpdatePage ( appUpdateText: text ) ) ) ;
}
}
get ( String endPoint ,
get ( String endPoint ,
@ -434,10 +388,7 @@ class BaseAppClient {
if ( await Utils . checkConnection ( ) ) {
if ( await Utils . checkConnection ( ) ) {
final response = await http . get (
final response = await http . get (
url . trim ( ) ,
url . trim ( ) ,
headers: {
headers: { ' Content-Type ' : ' application/json ' , ' Accept ' : ' application/json ' } ,
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json '
} ,
) ;
) ;
final int statusCode = response . statusCode ;
final int statusCode = response . statusCode ;
print ( " statusCode : $ statusCode " ) ;
print ( " statusCode : $ statusCode " ) ;
@ -481,9 +432,7 @@ class BaseAppClient {
' Content-Type ' : ' text/html; charset=utf-8 ' ,
' Content-Type ' : ' text/html; charset=utf-8 ' ,
' Accept ' : ' application/json ' ,
' Accept ' : ' application/json ' ,
' Authorization ' : token ? ? ' ' ,
' Authorization ' : token ? ? ' ' ,
' Mobilenumber ' : user ! = null
' Mobilenumber ' : user ! = null ? Utils . getPhoneNumberWithoutZero ( user [ ' MobileNumber ' ] . toString ( ) ) : " " ,
? Utils . getPhoneNumberWithoutZero ( user [ ' MobileNumber ' ] . toString ( ) )
: " " ,
' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Username ' : user ! = null ? user [ ' PatientID ' ] . toString ( ) : " " ,
' Username ' : user ! = null ? user [ ' PatientID ' ] . toString ( ) : " " ,
} ) ;
} ) ;
@ -492,8 +441,7 @@ class BaseAppClient {
if ( statusCode < 200 | | statusCode > = 400 | | json = = null ) {
if ( statusCode < 200 | | statusCode > = 400 | | json = = null ) {
if ( statusCode = = 401 ) {
if ( statusCode = = 401 ) {
AppToast . showErrorToast (
AppToast . showErrorToast ( message: TranslationBase . of ( AppGlobal . context ) . pharmacyRelogin ) ;
message: TranslationBase . of ( AppGlobal . context ) . pharmacyRelogin ) ;
Navigator . of ( AppGlobal . context ) . pushNamed ( HOME ) ;
Navigator . of ( AppGlobal . context ) . pushNamed ( HOME ) ;
} else {
} else {
onFailure ( ' Error While Fetching data ' , statusCode ) ;
onFailure ( ' Error While Fetching data ' , statusCode ) ;
@ -521,10 +469,7 @@ class BaseAppClient {
final response = await http . post (
final response = await http . post (
url . trim ( ) ,
url . trim ( ) ,
body: json . encode ( body ) ,
body: json . encode ( body ) ,
headers: {
headers: { ' Content-Type ' : ' application/json ' , ' Accept ' : ' application/json ' } ,
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json '
} ,
) ;
) ;
final int statusCode = response . statusCode ;
final int statusCode = response . statusCode ;
@ -557,10 +502,7 @@ class BaseAppClient {
if ( await Utils . checkConnection ( ) ) {
if ( await Utils . checkConnection ( ) ) {
final response = await http . get (
final response = await http . get (
url . trim ( ) ,
url . trim ( ) ,
headers: {
headers: { ' Content-Type ' : ' application/json ' , ' Accept ' : ' application/json ' } ,
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json '
} ,
) ;
) ;
final int statusCode = response . statusCode ;
final int statusCode = response . statusCode ;
@ -587,10 +529,7 @@ class BaseAppClient {
final response = await http . put (
final response = await http . put (
url . trim ( ) ,
url . trim ( ) ,
body: json . encode ( body ) ,
body: json . encode ( body ) ,
headers: {
headers: { ' Content-Type ' : ' application/json ' , ' Accept ' : ' application/json ' } ,
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json '
} ,
) ;
) ;
final int statusCode = response . statusCode ;
final int statusCode = response . statusCode ;
@ -623,10 +562,7 @@ class BaseAppClient {
if ( await Utils . checkConnection ( ) ) {
if ( await Utils . checkConnection ( ) ) {
final response = await http . delete (
final response = await http . delete (
url . trim ( ) ,
url . trim ( ) ,
headers: {
headers: { ' Content-Type ' : ' application/json ' , ' Accept ' : ' application/json ' } ,
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json '
} ,
) ;
) ;
final int statusCode = response . statusCode ;
final int statusCode = response . statusCode ;
@ -646,10 +582,8 @@ class BaseAppClient {
await sharedPref . remove ( LOGIN_TOKEN_ID ) ;
await sharedPref . remove ( LOGIN_TOKEN_ID ) ;
await sharedPref . remove ( PHARMACY_CUSTOMER_ID ) ;
await sharedPref . remove ( PHARMACY_CUSTOMER_ID ) ;
await authenticatedUserObject . getUser ( ) ;
await authenticatedUserObject . getUser ( ) ;
Provider . of < ProjectViewModel > ( AppGlobal . context , listen: false ) . isLogin =
Provider . of < ProjectViewModel > ( AppGlobal . context , listen: false ) . isLogin = false ;
false ;
var model = Provider . of < ToDoCountProviderModel > ( AppGlobal . context , listen: false ) ;
var model =
Provider . of < ToDoCountProviderModel > ( AppGlobal . context , listen: false ) ;
_vitalSignService . weightKg = " " ;
_vitalSignService . weightKg = " " ;
_vitalSignService . heightCm = " " ;
_vitalSignService . heightCm = " " ;
model . setState ( 0 , false ) ;
model . setState ( 0 , false ) ;
@ -663,8 +597,7 @@ class BaseAppClient {
static defaultHttpParameters ( ) async {
static defaultHttpParameters ( ) async {
String token = await sharedPref . getString ( TOKEN ) ;
String token = await sharedPref . getString ( TOKEN ) ;
var languageID =
var languageID = await sharedPref . getStringWithDefaultValue ( APP_LANGUAGE , ' ar ' ) ;
await sharedPref . getStringWithDefaultValue ( APP_LANGUAGE , ' ar ' ) ;
var user = await sharedPref . getObject ( USER_PROFILE ) ;
var user = await sharedPref . getObject ( USER_PROFILE ) ;
var params = { } ;
var params = { } ;
if ( user ! = null ) {
if ( user ! = null ) {
@ -700,8 +633,7 @@ class BaseAppClient {
try {
try {
if ( isExternal ) {
if ( isExternal ) {
String token = await sharedPref . getString ( TOKEN ) ;
String token = await sharedPref . getString ( TOKEN ) ;
var languageID =
var languageID = await sharedPref . getStringWithDefaultValue ( APP_LANGUAGE , ' ar ' ) ;
await sharedPref . getStringWithDefaultValue ( APP_LANGUAGE , ' ar ' ) ;
var user = await sharedPref . getObject ( USER_PROFILE ) ;
var user = await sharedPref . getObject ( USER_PROFILE ) ;
if ( body . containsKey ( ' SetupID ' ) ) {
if ( body . containsKey ( ' SetupID ' ) ) {
body [ ' SetupID ' ] = body . containsKey ( ' SetupID ' )
body [ ' SetupID ' ] = body . containsKey ( ' SetupID ' )
@ -724,8 +656,7 @@ class BaseAppClient {
: PATIENT_OUT_SA ;
: PATIENT_OUT_SA ;
if ( body . containsKey ( ' isDentalAllowedBackend ' ) ) {
if ( body . containsKey ( ' isDentalAllowedBackend ' ) ) {
body [ ' isDentalAllowedBackend ' ] =
body [ ' isDentalAllowedBackend ' ] = body . containsKey ( ' isDentalAllowedBackend ' )
body . containsKey ( ' isDentalAllowedBackend ' )
? body [ ' isDentalAllowedBackend ' ] ! = null
? body [ ' isDentalAllowedBackend ' ] ! = null
? body [ ' isDentalAllowedBackend ' ]
? body [ ' isDentalAllowedBackend ' ]
: IS_DENTAL_ALLOWED_BACKEND
: IS_DENTAL_ALLOWED_BACKEND
@ -752,9 +683,7 @@ class BaseAppClient {
: PATIENT_TYPE_ID ;
: PATIENT_TYPE_ID ;
if ( user ! = null ) {
if ( user ! = null ) {
body [ ' TokenID ' ] = token ;
body [ ' TokenID ' ] = token ;
body [ ' PatientID ' ] = body [ ' PatientID ' ] ! = null
body [ ' PatientID ' ] = body [ ' PatientID ' ] ! = null ? body [ ' PatientID ' ] : user [ ' PatientID ' ] ;
? body [ ' PatientID ' ]
: user [ ' PatientID ' ] ;
body [ ' PatientOutSA ' ] = user [ ' OutSA ' ] ;
body [ ' PatientOutSA ' ] = user [ ' OutSA ' ] ;
body [ ' SessionID ' ] = SESSION_ID ; / / getSessionId ( token ) ;
body [ ' SessionID ' ] = SESSION_ID ; / / getSessionId ( token ) ;
}
}
@ -766,17 +695,14 @@ class BaseAppClient {
var ss = json . encode ( body ) ;
var ss = json . encode ( body ) ;
if ( await Utils . checkConnection ( ) ) {
if ( await Utils . checkConnection ( ) ) {
final response =
final response = await http . post ( url . trim ( ) , body: json . encode ( body ) , headers: {
await http . post ( url . trim ( ) , body: json . encode ( body ) , headers: {
/ / ' Content-Type ' : ' application/json ' ,
/ / ' Content-Type ' : ' application/json ' ,
/ / ' Accept ' : ' application/json ' ,
/ / ' Accept ' : ' application/json ' ,
/ / ' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
/ / ' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Content-Type ' : ' application/json ' ,
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json ' ,
' Accept ' : ' application/json ' ,
' Authorization ' : token ? ? ' ' ,
' Authorization ' : token ? ? ' ' ,
' Mobilenumber ' : user ! = null
' Mobilenumber ' : user ! = null ? Utils . getPhoneNumberWithoutZero ( user [ ' MobileNumber ' ] . toString ( ) ) : " " ,
? Utils . getPhoneNumberWithoutZero ( user [ ' MobileNumber ' ] . toString ( ) )
: " " ,
' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Statictoken ' : ' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ' ,
' Username ' : user ! = null ? user [ ' PatientID ' ] . toString ( ) : " " ,
' Username ' : user ! = null ? user [ ' PatientID ' ] . toString ( ) : " " ,
} ) ;
} ) ;
@ -791,8 +717,7 @@ class BaseAppClient {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else {
} else {
if ( parsed [ ' ErrorType ' ] = = 4 ) {
if ( parsed [ ' ErrorType ' ] = = 4 ) {
navigateToAppUpdate (
navigateToAppUpdate ( AppGlobal . context , parsed [ ' ErrorEndUserMessage ' ] ) ;
AppGlobal . context , parsed [ ' ErrorEndUserMessage ' ] ) ;
}
}
if ( isAllowAny ) {
if ( isAllowAny ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
@ -807,31 +732,21 @@ class BaseAppClient {
if ( parsed ! = null ) {
if ( parsed ! = null ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else {
} else {
onFailure (
onFailure ( parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
logout ( ) ;
logout ( ) ;
}
}
}
}
} else if ( parsed [ ' MessageStatus ' ] = = 1 | |
} else if ( parsed [ ' MessageStatus ' ] = = 1 | | parsed [ ' SMSLoginRequired ' ] = = true ) {
parsed [ ' SMSLoginRequired ' ] = = true ) {
onSuccess ( parsed , statusCode ) ;
onSuccess ( parsed , statusCode ) ;
} else if ( parsed [ ' MessageStatus ' ] = = 2 & &
} else if ( parsed [ ' MessageStatus ' ] = = 2 & & parsed [ ' IsAuthenticated ' ] ) {
parsed [ ' IsAuthenticated ' ] ) {
if ( parsed [ ' message ' ] = = null & & parsed [ ' ErrorEndUserMessage ' ] = = null ) {
if ( parsed [ ' message ' ] = = null & &
parsed [ ' ErrorEndUserMessage ' ] = = null ) {
if ( parsed [ ' ErrorSearchMsg ' ] = = null ) {
if ( parsed [ ' ErrorSearchMsg ' ] = = null ) {
onFailure ( " Server Error found with no available message " ,
onFailure ( " Server Error found with no available message " , statusCode ) ;
statusCode ) ;
} else {
} else {
onFailure ( parsed [ ' ErrorSearchMsg ' ] , statusCode ) ;
onFailure ( parsed [ ' ErrorSearchMsg ' ] , statusCode ) ;
}
}
} else {
} else {
onFailure (
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' message ' ] ? ?
parsed [ ' ErrorEndUserMessage ' ] ? ?
parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
}
}
} else if ( ! parsed [ ' IsAuthenticated ' ] ) {
} else if ( ! parsed [ ' IsAuthenticated ' ] ) {
await logout ( ) ;
await logout ( ) ;
@ -844,9 +759,7 @@ class BaseAppClient {
if ( parsed [ ' message ' ] ! = null ) {
if ( parsed [ ' message ' ] ! = null ) {
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' message ' ] , statusCode ) ;
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' message ' ] , statusCode ) ;
} else {
} else {
onFailure (
onFailure ( parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
}
}
}
}
}
}