delete http intercceptor

merge-requests/104/head
Elham Rababah 6 years ago
parent d4ba01de5b
commit 02216b497c

@ -1,6 +1,5 @@
import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/interceptor/http_interceptor.dart'; import 'package:http/http.dart' as http;
import 'package:http/http.dart';
// OWNER : Ibrahim albitar // OWNER : Ibrahim albitar
// DATE : 22-04-2020 // DATE : 22-04-2020
@ -8,11 +7,12 @@ import 'package:http/http.dart';
class AppClient { class AppClient {
static Client client = HttpInterceptor().getClient(); static Future<dynamic> post(dynamic path, {dynamic body}) async {
static Future<Response> post(dynamic path, {dynamic body}) async {
String _fullUrl = BASE_URL + path; String _fullUrl = BASE_URL + path;
final response = await client.post(_fullUrl, body: body); final response = await http.post(_fullUrl, body: body, headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
});
return response; return response;
} }
} }

@ -2,14 +2,13 @@ import 'dart:convert';
import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/interceptor/http_interceptor.dart';
import 'package:doctor_app_flutter/models/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/doctor_profile_model.dart';
import 'package:doctor_app_flutter/routes.dart'; import 'package:doctor_app_flutter/routes.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart'; import 'package:http/http.dart' as http;
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
Helpers helpers = new Helpers(); Helpers helpers = new Helpers();
@ -29,7 +28,6 @@ Helpers helpers = new Helpers();
body: null); body: null);
* */ * */
class BaseAppClient { class BaseAppClient {
static Client client = HttpInterceptor().getClient();
static post( static post(
String endPoint, { String endPoint, {
@ -59,7 +57,12 @@ class BaseAppClient {
body['PatientOutSA'] = PATIENT_OUT_SA; body['PatientOutSA'] = PATIENT_OUT_SA;
if (await Helpers.checkConnection()) { if (await Helpers.checkConnection()) {
final response = await client.post(url, body: json.encode(body)); final response = await http.post(url,
body: json.encode(body),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
});
final int statusCode = response.statusCode; final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode >= 400 || json == null) { if (statusCode < 200 || statusCode >= 400 || json == null) {
onFailure('Error While Fetching data', statusCode); onFailure('Error While Fetching data', statusCode);

@ -1,65 +0,0 @@
import 'dart:convert';
import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/providers/auth_provider.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
import '../providers/auth_provider.dart';
import '../util/dr_app_shared_pref.dart';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
List<String> publicUrls = [
LOGIN_URL,
SELECT_DEVICE_IMEI,
MEMBER_CHECK_ACTIVATION_CODE_NEW,
SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE
];
class HttpInterceptor extends InterceptorContract {
Client getClient(){
return HttpClientWithInterceptor.build(interceptors: [this]);
}
Future<RequestData> interceptRequest({RequestData data}) async {
print('RequestData ${data.body}');
print('RequestData ${data.url}');
try {
data.headers["Content-Type"] = "application/json";
data.headers["Accept"] = "application/json";
// if (publicUrls.contains(data.url)) {
// var loggedUserInfo = await sharedPref.getObj('loggedUser');
// var token = await sharedPref.getString(TOKEN);
// // print("token"+token);
// // print('loggedUserInfo${loggedUserInfo["LogInTokenID"]}');
// // // the sevices handel the token in differat name so I ask to be change
// // // we must change the imple
// var body = json.decode(data.body);
// body['LogInTokenID']=token;
// data.body = json.encode(body);
// // data.body['LogInTokenID'] = '';
// } else {
// if (data.body['LogInTokenID']) {
// data.body['LogInTokenID'] = '';
// }
// if (data.body['TokenID']) {
// data.body['TokenID'] = '';
// }
// }
} catch (e) {
print(e);
}
// print('data.body${data.body}');
return data;
}
@override
Future<ResponseData> interceptResponse({ResponseData data}) async {
// print('ResponseData ${data.body}');
return data;
}
}

@ -17,12 +17,9 @@ import 'package:doctor_app_flutter/models/patient/radiology_res_model.dart';
import 'package:doctor_app_flutter/models/patient/refer_to_doctor_request.dart'; import 'package:doctor_app_flutter/models/patient/refer_to_doctor_request.dart';
import 'package:doctor_app_flutter/models/prescription_report.dart'; import 'package:doctor_app_flutter/models/prescription_report.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:http/http.dart';
import 'package:http_interceptor/http_client_with_interceptor.dart';
import '../client/app_client.dart'; import '../client/app_client.dart';
import '../config/config.dart'; import '../config/config.dart';
import '../interceptor/http_interceptor.dart';
import '../models/patient/lab_orders_res_model.dart'; import '../models/patient/lab_orders_res_model.dart';
import '../models/patient/patiant_info_model.dart'; import '../models/patient/patiant_info_model.dart';
import '../models/patient/patient_model.dart'; import '../models/patient/patient_model.dart';
@ -67,52 +64,46 @@ class PatientsProvider with ChangeNotifier {
ClinicByProjectIdRequest(); ClinicByProjectIdRequest();
ReferToDoctorRequest _referToDoctorRequest = ReferToDoctorRequest(); ReferToDoctorRequest _referToDoctorRequest = ReferToDoctorRequest();
Client client =
HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]);
PatiantInformtion _selectedPatient; PatiantInformtion _selectedPatient;
Future<Map> getPatientList(PatientModel patient, patientType) async { Future<Map> getPatientList(PatientModel patient, patientType) async {
/* const url =
BASE_URL+'DoctorApplication.svc/REST/GetMyInPatient';*/
int val = int.parse(patientType); int val = int.parse(patientType);
//**********Modify url by amjad amireh for patiant type*********
final url = final url =
BASE_URL + "DoctorApplication.svc/REST/" + SERVICES_PATIANT[val]; BASE_URL + "DoctorApplication.svc/REST/" + SERVICES_PATIANT[val];
// print("a===========$url=======a");
try { try {
final response = await client.post(url, await BaseAppClient.post(url,
body: json.encode({ onSuccess: (dynamic response, int statusCode) {
"ProjectID": patient.ProjectID, return Future.value(response);
"ClinicID": patient.ClinicID, }, onFailure: (String error, int statusCode) {
"DoctorID": patient.DoctorID, throw error;
"FirstName": patient.FirstName, }, body: {
"MiddleName": patient.MiddleName, "ProjectID": patient.ProjectID,
"LastName": patient.LastName, "ClinicID": patient.ClinicID,
"PatientMobileNumber": patient.PatientMobileNumber, "DoctorID": patient.DoctorID,
"PatientIdentificationID": patient.PatientIdentificationID, "FirstName": patient.FirstName,
"PatientID": patient.PatientID, "MiddleName": patient.MiddleName,
"From": patient.From, "LastName": patient.LastName,
"To": patient.To, "PatientMobileNumber": patient.PatientMobileNumber,
"LanguageID": patient.LanguageID, "PatientIdentificationID": patient.PatientIdentificationID,
"stamp": patient.stamp, "PatientID": patient.PatientID,
"IPAdress": patient.IPAdress, "From": patient.From,
"VersionID": patient.VersionID, "To": patient.To,
"Channel": patient.Channel, "LanguageID": patient.LanguageID,
"TokenID": patient.TokenID, "stamp": patient.stamp,
"SessionID": patient.SessionID, "IPAdress": patient.IPAdress,
"IsLoginForDoctorApp": patient.IsLoginForDoctorApp, "VersionID": patient.VersionID,
"PatientOutSA": patient.PatientOutSA "Channel": patient.Channel,
})); "TokenID": patient.TokenID,
//********************** "SessionID": patient.SessionID,
//*********************** "IsLoginForDoctorApp": patient.IsLoginForDoctorApp,
"PatientOutSA": patient.PatientOutSA
return Future.value(json.decode(response.body)); });
} catch (err) { } catch (err) {
throw err; handelCatchErrorCase(error);
} }
} }
@ -239,7 +230,7 @@ class PatientsProvider with ChangeNotifier {
try { try {
if (await Helpers.checkConnection()) { if (await Helpers.checkConnection()) {
final response = final response =
await AppClient.post(GET_PRESCRIPTION, body: json.encode(patient)); await AppClient.post(GET_PRESCRIPTION, body: json.encode(patient));
final int statusCode = response.statusCode; final int statusCode = response.statusCode;
isLoading = false; isLoading = false;
@ -302,22 +293,20 @@ class PatientsProvider with ChangeNotifier {
} }
} }
getPrescriptionReport(prescriptionReqModel) async{ getPrescriptionReport(prescriptionReqModel) async {
prescriptionReport = []; prescriptionReport = [];
isLoading = true; isLoading = true;
isError = false; isError = false;
error = ""; error = "";
notifyListeners(); notifyListeners();
await BaseAppClient.post( await BaseAppClient.post('Patients.svc/REST/GetPrescriptionReport',
'Patients.svc/REST/GetPrescriptionReport',
onSuccess: (dynamic response, int statusCode) { onSuccess: (dynamic response, int statusCode) {
response['ListPRM'].forEach((v) { response['ListPRM'].forEach((v) {
prescriptionReport prescriptionReport.add(PrescriptionReport.fromJson(v));
.add(PrescriptionReport.fromJson(v)); });
}); isError = false;
isError = false; isLoading = false;
isLoading = false; }, onFailure: (String error, int statusCode) {
}, onFailure: (String error, int statusCode) {
isError = true; isError = true;
isLoading = false; isLoading = false;
this.error = error; this.error = error;
@ -661,31 +650,27 @@ class PatientsProvider with ChangeNotifier {
final int statusCode = response.statusCode; final int statusCode = response.statusCode;
isLoading = false; isLoading = false;
if (statusCode < 200 || statusCode >= 400 || json == null) { if (statusCode < 200 || statusCode >= 400 || json == null) {
isError = true; isError = true;
error = 'Error While Fetching data'; error = 'Error While Fetching data';
} else {
var res = json.decode(response.body);
print('$res');
if (res['MessageStatus'] == 1) {
patientProgressNoteList = res['List_GetPregressNoteForInPatient'];
} else { } else {
var res = json.decode(response.body); isError = true;
print('$res'); error = res['ErrorMessage'] ?? res['ErrorEndUserMessage'];
if (res['MessageStatus'] == 1) {
patientProgressNoteList = res['List_GetPregressNoteForInPatient'];
} else {
isError = true;
error = res['ErrorMessage'] ?? res['ErrorEndUserMessage'];
}
} }
} else {
isLoading = false;
isError = true;
error = 'Please Check The Internet Connection';
} }
notifyListeners(); } else {
} catch (err) { isLoading = false;
handelCatchErrorCase(err); isError = true;
error = 'Please Check The Internet Connection';
} }
notifyListeners();
} catch (err) {
handelCatchErrorCase(err);
} }
}
} }

Loading…
Cancel
Save