add interceptor

merge-requests/1/merge
Elham Rababah 5 years ago
parent 5bee9d1984
commit 9d4d9b026d

@ -0,0 +1,23 @@
import 'package:http_interceptor/http_interceptor.dart';
class HttpInterceptor extends InterceptorContract {
Future<RequestData> interceptRequest({RequestData data}) async {
print('RequestData ${data.body}');
try {
// data.params['appid'] = OPEN_WEATHER_API_KEY;
// data.params['units'] = 'metric';
data.headers["Content-Type"] = "application/json";
data.headers["Accept"] = "application/json";
} catch (e) {
print(e);
}
return data;
}
@override
Future<ResponseData> interceptResponse({ResponseData data}) async {
print('${data.body}');
return data;
}
}

@ -1,7 +1,9 @@
import 'dart:convert';
import 'package:doctor_app_flutter/interceptor/http_interceptor.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:http_interceptor/http_client_with_interceptor.dart';
import '../models/user_model.dart';
@ -9,18 +11,18 @@ const LOGIN_URL =
'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New';
const INSERT_DEVICE_IMEI =
'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI';
const SELECT_DEVICE_IMEI ='https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI';
const SELECT_DEVICE_IMEI =
'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI';
class AuthProvider with ChangeNotifier {
Client client =
HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]);
Future<Map> login(UserModel userInfo) async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
const url = LOGIN_URL;
try {
final response = await http.post(url,
headers: requestHeaders,
final response = await client.post(url,
// headers: requestHeaders,
body: json.encode({
"UserID": userInfo.UserID,
"Password": userInfo.Password,
@ -39,15 +41,10 @@ class AuthProvider with ChangeNotifier {
}
Future<Map> insertDeviceImei(imei) async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
const url = INSERT_DEVICE_IMEI;
try {
final response = await http.post(url,
headers: requestHeaders, body: json.encode(imei));
final response = await client.post(url, body: json.encode(imei));
return Future.value(json.decode(response.body));
} catch (error) {
print(error);
@ -56,15 +53,10 @@ class AuthProvider with ChangeNotifier {
}
Future<Map> selectDeviceImei(imei) async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
const url = SELECT_DEVICE_IMEI;
try {
final response = await http.post(url,
headers: requestHeaders, body: json.encode(imei));
final response = await client.post(url, body: json.encode(imei));
return Future.value(json.decode(response.body));
} catch (error) {
print(error);

@ -1,20 +1,20 @@
import 'dart:convert';
import 'package:doctor_app_flutter/models/patient_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:http_interceptor/http_client_with_interceptor.dart';
import '../interceptor/http_interceptor.dart';
import '../models/patient_model.dart';
class PatientsProvider with ChangeNotifier {
Client client =
HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]);
Future<Map> getPatientList(PatientModel patient, patientType) async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
const url =
'https://hmgwebservices.com/Services/DoctorApplication.svc/REST/GetMyInPatient';
try {
final response = await http.post(url,
headers: requestHeaders,
final response = await client.post(url,
body: json.encode({
"ProjectID": patient.PatientID,
"ClinicID": patient.ClinicID,

@ -1,17 +1,17 @@
import 'dart:convert';
import '../interceptor/http_interceptor.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:http_interceptor/http_client_with_interceptor.dart';
const GET_PROJECTS =
'https://hmgwebservices.com/Services/Lists.svc/REST/GetProjectForDoctorAPP';
class ProjectsProvider with ChangeNotifier {
Client client =
HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]);
Future<Map> getProjectsList() async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
const url = GET_PROJECTS;
var info = {
"LanguageID": 2,
@ -24,8 +24,7 @@ class ProjectsProvider with ChangeNotifier {
"IsLoginForDoctorApp": true
};
try {
final response = await http.post(url,
headers: requestHeaders, body: json.encode(info));
final response = await client.post(url, body: json.encode(info));
return Future.value(json.decode(response.body));
} catch (error) {
throw error;

@ -261,6 +261,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0+4"
http_interceptor:
dependency: "direct main"
description:
name: http_interceptor
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
http_multi_server:
dependency: transitive
description:

@ -29,6 +29,7 @@ dependencies:
imei_plugin: ^1.1.6
flutter_flexible_toast: ^0.1.4
local_auth: ^0.6.1+3
http_interceptor: ^0.2.0

Loading…
Cancel
Save