App client + Base URL

merge-requests/22/head
unknown 6 years ago
parent 46c927b183
commit aac1e5d241

@ -0,0 +1,14 @@
import 'package:doctor_app_flutter/interceptor/http_interceptor.dart';
import 'package:http/http.dart';
class AppClient {
static const String BASE_URL = "https://hmgwebservices.com/";
static Client client = HttpInterceptor().getClient();
static Future<Response> post(dynamic path, {dynamic body}) async {
String _fullUrl = BASE_URL + path;
final response = await client.post(_fullUrl, body: body);
return response;
}
}

@ -3,6 +3,7 @@ import 'dart:convert';
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/providers/auth_provider.dart'; import 'package:doctor_app_flutter/providers/auth_provider.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:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart'; import 'package:http_interceptor/http_interceptor.dart';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
@ -14,6 +15,11 @@ List<String> publicUrls = [
]; ];
class HttpInterceptor extends InterceptorContract { class HttpInterceptor extends InterceptorContract {
Client getClient(){
return HttpClientWithInterceptor.build(interceptors: [this]);
}
Future<RequestData> interceptRequest({RequestData data}) async { Future<RequestData> interceptRequest({RequestData data}) async {
// print('RequestData ${data.body}'); // print('RequestData ${data.body}');
try { try {

@ -1,32 +1,26 @@
import 'dart:convert'; import 'dart:convert';
import 'package:doctor_app_flutter/client/app_client.dart';
import 'package:doctor_app_flutter/interceptor/http_interceptor.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 '../models/user_model.dart'; import '../models/user_model.dart';
const LOGIN_URL = const LOGIN_URL =
'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New'; 'Services/Sentry.svc/REST/MemberLogIN_New';
const INSERT_DEVICE_IMEI = const INSERT_DEVICE_IMEI =
'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; 'Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI';
const SELECT_DEVICE_IMEI = const SELECT_DEVICE_IMEI =
'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI'; 'Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI';
const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE = const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE =
'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType'; 'Services/Sentry.svc/REST/DoctorApplication_SendActivationCodebyOTPNotificationType';
const MEMBER_CHECK_ACTIVATION_CODE_NEW ='https://hmgwebservices.com/Services/Sentry.svc/REST/MemberCheckActivationCode_New'; const MEMBER_CHECK_ACTIVATION_CODE_NEW ='Services/Sentry.svc/REST/MemberCheckActivationCode_New';
class AuthProvider with ChangeNotifier { class AuthProvider with ChangeNotifier {
Client client =
HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]);
Future<Map> login(UserModel userInfo) async { Future<Map> login(UserModel userInfo) async {
const url = LOGIN_URL; const url = LOGIN_URL;
try { try {
final response = await client.post(url, final response = await AppClient.post(url,
// headers: requestHeaders,
body: json.encode({ body: json.encode({
"UserID": userInfo.UserID, "UserID": userInfo.UserID,
"Password": userInfo.Password, "Password": userInfo.Password,
@ -48,7 +42,7 @@ class AuthProvider with ChangeNotifier {
const url = INSERT_DEVICE_IMEI; const url = INSERT_DEVICE_IMEI;
try { try {
final response = await client.post(url, body: json.encode(imei)); final response = await AppClient.post(url, body: json.encode(imei));
return Future.value(json.decode(response.body)); return Future.value(json.decode(response.body));
} catch (error) { } catch (error) {
print(error); print(error);
@ -60,7 +54,7 @@ class AuthProvider with ChangeNotifier {
const url = SELECT_DEVICE_IMEI; const url = SELECT_DEVICE_IMEI;
try { try {
final response = await client.post(url, body: json.encode(imei)); final response = await AppClient.post(url, body: json.encode(imei));
return Future.value(json.decode(response.body)); return Future.value(json.decode(response.body));
} catch (error) { } catch (error) {
print(error); print(error);
@ -72,7 +66,7 @@ class AuthProvider with ChangeNotifier {
const url = SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE; const url = SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE;
try { try {
final response = await client.post(url, body: json.encode(activationCodeModel)); final response = await AppClient.post(url, body: json.encode(activationCodeModel));
return Future.value(json.decode(response.body)); return Future.value(json.decode(response.body));
} catch (error) { } catch (error) {
print(error); print(error);
@ -84,7 +78,7 @@ class AuthProvider with ChangeNotifier {
const url = MEMBER_CHECK_ACTIVATION_CODE_NEW; const url = MEMBER_CHECK_ACTIVATION_CODE_NEW;
try { try {
final response = await client.post(url, body: json.encode(activationCodeModel)); final response = await AppClient.post(url, body: json.encode(activationCodeModel));
return Future.value(json.decode(response.body)); return Future.value(json.decode(response.body));
} catch (error) { } catch (error) {
print(error); print(error);

Loading…
Cancel
Save