|
|
|
|
@ -3,14 +3,9 @@ import 'dart:convert';
|
|
|
|
|
import 'package:doctor_app_flutter/config/config.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/models/doctor_profile_model.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/helpers.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
import 'package:http_interceptor/http_methods.dart';
|
|
|
|
|
import 'package:http_interceptor/models/request_data.dart';
|
|
|
|
|
|
|
|
|
|
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
|
|
|
|
|
Helpers helpers = new Helpers();
|
|
|
|
|
@ -32,15 +27,12 @@ Helpers helpers = new Helpers();
|
|
|
|
|
* */
|
|
|
|
|
class BaseAppClient {
|
|
|
|
|
static post(
|
|
|
|
|
String endPoint, {
|
|
|
|
|
Map<String, dynamic> body,
|
|
|
|
|
Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
|
Function(String error, int statusCode) onFailure,
|
|
|
|
|
}) async {
|
|
|
|
|
String endPoint, {
|
|
|
|
|
Map<String, dynamic> body,
|
|
|
|
|
Function(dynamic response, int statusCode) onSuccess,
|
|
|
|
|
Function(String error, int statusCode) onFailure,
|
|
|
|
|
}) async {
|
|
|
|
|
String url = BASE_URL + endPoint;
|
|
|
|
|
RequestData data = RequestData(body: body,baseUrl: url,method: Method.POST);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Map profile = await sharedPref.getObj(DOCTOR_PROFILE);
|
|
|
|
|
String token = await sharedPref.getString(TOKEN);
|
|
|
|
|
@ -49,8 +41,8 @@ class BaseAppClient {
|
|
|
|
|
body['DoctorID'] = doctorProfile?.doctorID;
|
|
|
|
|
body['EditedBy'] = doctorProfile?.doctorID;
|
|
|
|
|
body['ProjectID'] = doctorProfile?.projectID;
|
|
|
|
|
// if (!body.containsKey('ClinicID'))
|
|
|
|
|
body['ClinicID'] = doctorProfile?.clinicID;
|
|
|
|
|
// if (!body.containsKey('ClinicID'))
|
|
|
|
|
body['ClinicID'] = doctorProfile?.clinicID;
|
|
|
|
|
}
|
|
|
|
|
body['TokenID'] = token ?? '';
|
|
|
|
|
body['LanguageID'] = LANGUAGE_ID;
|
|
|
|
|
@ -64,7 +56,7 @@ class BaseAppClient {
|
|
|
|
|
print("URL : $url");
|
|
|
|
|
print("Body : ${json.encode(body)}");
|
|
|
|
|
|
|
|
|
|
if (await Helpers.checkConnection()) {
|
|
|
|
|
if (await Helpers.checkConnection()) {
|
|
|
|
|
final response = await http.post(url,
|
|
|
|
|
body: json.encode(body),
|
|
|
|
|
headers: {
|
|
|
|
|
@ -77,7 +69,8 @@ class BaseAppClient {
|
|
|
|
|
} else {
|
|
|
|
|
var parsed = json.decode(response.body.toString());
|
|
|
|
|
if (!parsed['IsAuthenticated']) {
|
|
|
|
|
Navigator.of(AppGlobal.CONTEX).pushNamed(LOGIN);
|
|
|
|
|
await helpers.logout();
|
|
|
|
|
|
|
|
|
|
helpers.showErrorToast('Your session expired Please login agian');
|
|
|
|
|
} else if (parsed['MessageStatus'] == 1) {
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
|