import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; import 'package:flutter/cupertino.dart'; import 'package:doctor_app_flutter/config/config.dart'; import '../models/doctor/user_model.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED } class AuthProvider with ChangeNotifier { List doctorsClinicList = []; String selectedClinicName; bool isLogin = false; bool isLoading = true; DoctorProfileModel doctorProfile; setDoctorProfile(DoctorProfileModel profileModel){ doctorProfile = profileModel; notifyListeners(); } AuthProvider() { getUserAuthentication(); } getUserAuthentication() async { Map profile = await sharedPref.getObj(DOCTOR_PROFILE); if (profile != null) { doctorProfile = new DoctorProfileModel.fromJson(profile); isLoading = false; isLogin = true; } else { isLoading = false; isLogin = false; } notifyListeners(); } APP_STATUS get stutas { if (isLoading) { return APP_STATUS.LOADING; } else { if (this.isLogin) { return APP_STATUS.AUTHENTICATED; } else { return APP_STATUS.UNAUTHENTICATED; } } } Future login(UserModel userInfo) async { try { dynamic localRes; await BaseAppClient.post(LOGIN_URL, onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { throw error; }, body: userInfo.toJson()); return Future.value(localRes); } catch (error) { print(error); throw error; } } Future insertDeviceImei(imei) async { try { dynamic localRes; await BaseAppClient.post(INSERT_DEVICE_IMEI, onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { throw error; }, body: imei); return Future.value(localRes); } catch (error) { print(error); throw error; } } Future selectDeviceImei(imei) async { try { dynamic localRes; await BaseAppClient.post(SELECT_DEVICE_IMEI, onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { throw error; }, body: imei); return Future.value(localRes); } catch (error) { print(error); throw error; } } Future sendActivationCodeByOtpNotificationType(activationCodeModel) async { try { var localRes; await BaseAppClient.post(SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE, onSuccess: (dynamic response, int statusCode) { localRes = response; }, onFailure: (String error, int statusCode) { throw error; }, body: activationCodeModel); return Future.value(localRes); } catch (error) { print(error); throw error; } } Future memberCheckActivationCodeNew(activationCodeModel) async { try { dynamic localRes; await BaseAppClient.post(MEMBER_CHECK_ACTIVATION_CODE_NEW, onSuccess: (dynamic response, int statusCode) { localRes = response; selectedClinicName = ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName; response['List_DoctorsClinic'].forEach((v) { doctorsClinicList.add(new ClinicModel.fromJson(v)); }); }, onFailure: (String error, int statusCode) { throw error; }, body: activationCodeModel); return Future.value(localRes); } catch (error) { print(error); throw error; } } /* *@author: Elham Rababah *@Date:17/5/2020 *@param: docInfo *@return:Future *@desc: getDocProfiles */ Future getDocProfiles(docInfo) async { try { dynamic localRes; await BaseAppClient.post(GET_DOC_PROFILES, onSuccess: (dynamic response, int statusCode) { localRes = response; doctorProfile = DoctorProfileModel.fromJson(response['DoctorProfileList'][0]); selectedClinicName = response['DoctorProfileList'][0]['ClinicDescription']; }, onFailure: (String error, int statusCode) { throw error; }, body: docInfo); notifyListeners(); return Future.value(localRes); } catch (error) { print(error); throw error; } } }