do some refactor and change the code to view model

auth_refactor
Elham Rababah 5 years ago
parent 7dbd4c9cc6
commit fd9f93a936

@ -322,4 +322,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 649616dc336b3659ac6b2b25159d8e488e042b69 PODFILE CHECKSUM: 649616dc336b3659ac6b2b25159d8e488e042b69
COCOAPODS: 1.10.1 COCOAPODS: 1.10.0.rc.1

@ -21,4 +21,26 @@ extension SelectedAuthMethodTypesService on AuthMethodTypes {
} }
} }
// ignore: missing_return
static getMethodsTypeService( int typeId) {
switch (typeId) {
case 1:
return AuthMethodTypes.SMS;
break;
case 2:
return AuthMethodTypes.WhatsApp;
break;
case 3:
return AuthMethodTypes.Fingerprint;
break;
case 4:
return AuthMethodTypes.FaceID;
break;
case 5:
return AuthMethodTypes.MoreOptions;
break;
}
}
} }

@ -1,24 +1,33 @@
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
class CheckActivationCodeForDoctorAppResponseModel { class CheckActivationCodeForDoctorAppResponseModel {
String authenticationTokenID; String authenticationTokenID;
List<ListDoctorsClinic> listDoctorsClinic; List<ListDoctorsClinic> listDoctorsClinic;
List<dynamic> list_DoctorProfile; List<DoctorProfileModel> listDoctorProfile;
MemberInformation memberInformation; MemberInformation memberInformation;
CheckActivationCodeForDoctorAppResponseModel( CheckActivationCodeForDoctorAppResponseModel(
{this.authenticationTokenID, {this.authenticationTokenID,
this.listDoctorsClinic, this.listDoctorsClinic,
this.memberInformation}); this.memberInformation});
CheckActivationCodeForDoctorAppResponseModel.fromJson( CheckActivationCodeForDoctorAppResponseModel.fromJson(
Map<String, dynamic> json) { Map<String, dynamic> json) {
authenticationTokenID = json['AuthenticationTokenID']; authenticationTokenID = json['AuthenticationTokenID'];
list_DoctorProfile = json['List_DoctorProfile'];
if (json['List_DoctorsClinic'] != null) { if (json['List_DoctorsClinic'] != null) {
listDoctorsClinic = new List<ListDoctorsClinic>(); listDoctorsClinic = new List<ListDoctorsClinic>();
json['List_DoctorsClinic'].forEach((v) { json['List_DoctorsClinic'].forEach((v) {
listDoctorsClinic.add(new ListDoctorsClinic.fromJson(v)); listDoctorsClinic.add(new ListDoctorsClinic.fromJson(v));
}); });
} }
if (json['List_DoctorProfile'] != null) {
listDoctorProfile = new List<DoctorProfileModel>();
json['List_DoctorProfile'].forEach((v) {
listDoctorProfile.add(new DoctorProfileModel.fromJson(v));
});
}
memberInformation = json['memberInformation'] != null memberInformation = json['memberInformation'] != null
? new MemberInformation.fromJson(json['memberInformation']) ? new MemberInformation.fromJson(json['memberInformation'])
: null; : null;
@ -27,11 +36,15 @@ class CheckActivationCodeForDoctorAppResponseModel {
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>(); final Map<String, dynamic> data = new Map<String, dynamic>();
data['AuthenticationTokenID'] = this.authenticationTokenID; data['AuthenticationTokenID'] = this.authenticationTokenID;
data['List_DoctorProfile'] = this.list_DoctorProfile;
if (this.listDoctorsClinic != null) { if (this.listDoctorsClinic != null) {
data['List_DoctorsClinic'] = data['List_DoctorsClinic'] =
this.listDoctorsClinic.map((v) => v.toJson()).toList(); this.listDoctorsClinic.map((v) => v.toJson()).toList();
} }
if (this.listDoctorProfile != null) {
data['List_DoctorProfile'] =
this.listDoctorProfile.map((v) => v.toJson()).toList();
}
if (this.memberInformation != null) { if (this.memberInformation != null) {
data['memberInformation'] = this.memberInformation.toJson(); data['memberInformation'] = this.memberInformation.toJson();
} }
@ -47,13 +60,12 @@ class ListDoctorsClinic {
bool isActive; bool isActive;
String clinicName; String clinicName;
ListDoctorsClinic( ListDoctorsClinic({this.setupID,
{this.setupID, this.projectID,
this.projectID, this.doctorID,
this.doctorID, this.clinicID,
this.clinicID, this.isActive,
this.isActive, this.clinicName});
this.clinicName});
ListDoctorsClinic.fromJson(Map<String, dynamic> json) { ListDoctorsClinic.fromJson(Map<String, dynamic> json) {
setupID = json['SetupID']; setupID = json['SetupID'];
@ -87,16 +99,15 @@ class MemberInformation {
String preferredLanguage; String preferredLanguage;
List<Roles> roles; List<Roles> roles;
MemberInformation( MemberInformation({this.clinics,
{this.clinics, this.doctorId,
this.doctorId, this.email,
this.email, this.employeeId,
this.employeeId, this.memberId,
this.memberId, this.memberName,
this.memberName, this.memberNameArabic,
this.memberNameArabic, this.preferredLanguage,
this.preferredLanguage, this.roles});
this.roles});
MemberInformation.fromJson(Map<String, dynamic> json) { MemberInformation.fromJson(Map<String, dynamic> json) {
if (json['clinics'] != null) { if (json['clinics'] != null) {

@ -10,6 +10,8 @@ import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart
import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart';
import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart';
import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart';
import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -30,6 +32,9 @@ class AuthenticationService extends BaseService {
CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes;
Map<String, dynamic> _insertDeviceImeiRes = {}; Map<String, dynamic> _insertDeviceImeiRes = {};
List<DoctorProfileModel> _doctorProfilesList = [];
List<DoctorProfileModel> get doctorProfilesList => _doctorProfilesList;
Future selectDeviceImei(imei) async { Future selectDeviceImei(imei) async {
try { try {
await baseAppClient.post(SELECT_DEVICE_IMEI, await baseAppClient.post(SELECT_DEVICE_IMEI,
@ -144,4 +149,23 @@ class AuthenticationService extends BaseService {
super.error = error; super.error = error;
} }
} }
Future getDoctorProfileBasedOnClinic(ProfileReqModel profileReqModel)async {
hasError = false;
try {
await baseAppClient.post(GET_DOC_PROFILES,
onSuccess: (dynamic response, int statusCode) {
_doctorProfilesList.clear();
response['DoctorProfileList'].forEach((v) {
_doctorProfilesList.add(DoctorProfileModel.fromJson(v));
});
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
}, body: profileReqModel.toJson());
} catch (error) {
hasError = true;
super.error = error;
}
}
} }

@ -3,36 +3,62 @@ import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/core/model/auth/activation_Code_req_model.dart';
import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart';
import 'package:doctor_app_flutter/core/model/auth/check_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/check_activation_code_for_doctor_app_response_model.dart';
import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart';
import 'package:doctor_app_flutter/core/model/auth/imei_details.dart';
import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart';
import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart';
import 'package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart';
import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart';
import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart';
import 'package:doctor_app_flutter/core/model/auth/imei_details.dart';
import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/service/authentication_service.dart';
import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/locator.dart'; import 'package:doctor_app_flutter/locator.dart';
import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart';
import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:intl/intl.dart'; import 'package:flutter/services.dart';
import 'package:local_auth/auth_strings.dart';
import 'package:local_auth/local_auth.dart';
import 'package:provider/provider.dart';
import 'doctor_profile_view_model.dart';
class AuthenticationViewModel extends BaseViewModel { class AuthenticationViewModel extends BaseViewModel {
AuthenticationService _authService = locator<AuthenticationService>(); AuthenticationService _authService = locator<AuthenticationService>();
HospitalsService _hospitalsService = locator<HospitalsService>(); HospitalsService _hospitalsService = locator<HospitalsService>();
List<GetIMEIDetailsModel> get imeiDetails => _authService.dashboardItemsList; List<GetIMEIDetailsModel> get imeiDetails => _authService.dashboardItemsList;
List<GetHospitalsResponseModel> get hospitals => _hospitalsService.hospitals; List<GetHospitalsResponseModel> get hospitals => _hospitalsService.hospitals;
NewLoginInformationModel get loginInfo => _authService.loginInfo; NewLoginInformationModel get loginInfo => _authService.loginInfo;
SendActivationCodeForDoctorAppResponseModel get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes; List<DoctorProfileModel> get doctorProfilesList => _authService.doctorProfilesList;
SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes; SendActivationCodeForDoctorAppResponseModel
CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; get activationCodeVerificationScreenRes =>
_authService.activationCodeVerificationScreenRes;
SendActivationCodeForDoctorAppResponseModel
get activationCodeForDoctorAppRes =>
_authService.activationCodeForDoctorAppRes;
CheckActivationCodeForDoctorAppResponseModel
get checkActivationCodeForDoctorAppRes =>
_authService.checkActivationCodeForDoctorAppRes;
NewLoginInformationModel loggedUser; NewLoginInformationModel loggedUser;
GetIMEIDetailsModel user; GetIMEIDetailsModel user;
UserModel userInfo = UserModel();
final LocalAuthentication auth = LocalAuthentication();
List<BiometricType> _availableBiometrics;
Future selectDeviceImei(imei) async { Future selectDeviceImei(imei) async {
setState(ViewState.Busy); setState(ViewState.Busy);
await _authService.selectDeviceImei(imei); await _authService.selectDeviceImei(imei);
@ -88,8 +114,13 @@ class AuthenticationViewModel extends BaseViewModel {
if (_authService.hasError) { if (_authService.hasError) {
error = _authService.error; error = _authService.error;
setState(ViewState.ErrorLocal); setState(ViewState.ErrorLocal);
} else } else {
sharedPref.setInt(PROJECT_ID, userInfo.projectID);
saveObjToString(LOGGED_IN_USER, loginInfo);
sharedPref.remove(LAST_LOGIN_USER);
sharedPref.setString(TOKEN, loginInfo.logInTokenID);
setState(ViewState.Idle); setState(ViewState.Idle);
}
} }
Future sendActivationCodeVerificationScreen( AuthMethodTypes authMethodType) async { Future sendActivationCodeVerificationScreen( AuthMethodTypes authMethodType) async {
@ -168,21 +199,6 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
//TODO Elham remove it
getDate(DateTime date) {
final DateFormat formatter = DateFormat('dd MMM yyyy');
return formatter.format(date);
}
//TODO Elham remove it
getTime(DateTime date) {
final DateFormat formatter = DateFormat('HH:mm a');
return formatter.format(date);
}
getType(type, context) { getType(type, context) {
switch (type) { switch (type) {
case 1: case 1:
@ -214,17 +230,16 @@ class AuthenticationViewModel extends BaseViewModel {
var localLoggedUser = await sharedPref.getObj(LOGGED_IN_USER); var localLoggedUser = await sharedPref.getObj(LOGGED_IN_USER);
if(localLoggedUser!= null) { if(localLoggedUser!= null) {
loggedUser = NewLoginInformationModel.fromJson(localLoggedUser); loggedUser = NewLoginInformationModel.fromJson(localLoggedUser);
} }
var lastLogin = await sharedPref.getObj(LAST_LOGIN_USER); var lastLogin = await sharedPref.getObj(LAST_LOGIN_USER);
if (lastLogin != null) { if (lastLogin != null) {
user = GetIMEIDetailsModel.fromJson(lastLogin); user = GetIMEIDetailsModel.fromJson(lastLogin);
} }
setState(ViewState.Idle); setState(ViewState.Idle);
} }
setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel){ setDataAfterSendActivationSuccsess(
SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) {
print("VerificationCode : " + print("VerificationCode : " +
sendActivationCodeForDoctorAppResponseModel.verificationCode); sendActivationCodeForDoctorAppResponseModel.verificationCode);
sharedPref.setString(VIDA_AUTH_TOKEN_ID, sharedPref.setString(VIDA_AUTH_TOKEN_ID,
@ -234,4 +249,93 @@ class AuthenticationViewModel extends BaseViewModel {
sharedPref.setString(LOGIN_TOKEN_ID, sharedPref.setString(LOGIN_TOKEN_ID,
sendActivationCodeForDoctorAppResponseModel.logInTokenID); sendActivationCodeForDoctorAppResponseModel.logInTokenID);
} }
saveObjToString(String key, value) async {
sharedPref.setObj(key, value);
}
showIOSAuthMessages() async {
const iosStrings = const IOSAuthMessages(
cancelButton: 'cancel',
goToSettingsButton: 'settings',
goToSettingsDescription: 'Please set up your Touch ID.',
lockOut: 'Please Enable Your Touch ID');
try {
await auth.authenticateWithBiometrics(
localizedReason: 'Scan your fingerprint to authenticate',
useErrorDialogs: true,
stickyAuth: true,
iOSAuthStrings: iosStrings);
} on PlatformException catch (e) {
DrAppToastMsg.showErrorToast(e.toString());
}
}
localSetDoctorProfile(DoctorProfileModel profile) {
super.setDoctorProfile(profile);
//TODO: Remove it when we remove Doctor Profile View Model and start to use profile form base view model
Provider.of<DoctorProfileViewModel>(AppGlobal.CONTEX, listen: false)
.setDoctorProfile(profile);
}
Future getDoctorProfileBasedOnClinic(ClinicModel clinicInfo) async {
ProfileReqModel docInfo = new ProfileReqModel(
doctorID: clinicInfo.doctorID,
clinicID: clinicInfo.clinicID,
license: true,
projectID: clinicInfo.projectID,
tokenID: '',
languageID: 2);
await _authService.getDoctorProfileBasedOnClinic(docInfo);
if (_authService.hasError) {
error = _authService.error;
setState(ViewState.ErrorLocal);
} else {
localSetDoctorProfile(doctorProfilesList.first);
setState(ViewState.Idle);
}
}
onCheckActivationCodeSuccess() async {
sharedPref.setString(
TOKEN,
checkActivationCodeForDoctorAppRes.authenticationTokenID);
if (checkActivationCodeForDoctorAppRes.listDoctorProfile != null &&
checkActivationCodeForDoctorAppRes.listDoctorProfile
.isNotEmpty) {
localSetDoctorProfile(
checkActivationCodeForDoctorAppRes.listDoctorProfile[0]);
} else {
sharedPref.setObj(
CLINIC_NAME,
checkActivationCodeForDoctorAppRes.listDoctorsClinic);
ClinicModel clinic = ClinicModel.fromJson(
checkActivationCodeForDoctorAppRes.listDoctorsClinic[0]
.toJson());
await getDoctorProfileBasedOnClinic(clinic);
}
}
Future <bool> checkIfBiometricAvailable(BiometricType biometricType) async {
bool isAvailable = false;
await _getAvailableBiometrics();
if (_availableBiometrics != null) {
for (var i = 0; i < _availableBiometrics.length; i++) {
if (biometricType == _availableBiometrics[i]) isAvailable = true;
}
}
return isAvailable;
}
Future<void> _getAvailableBiometrics() async {
try {
_availableBiometrics = await auth.getAvailableBiometrics();
} on PlatformException catch (e) {
print(e);
}
}
} }

@ -45,5 +45,10 @@ class BaseViewModel extends ChangeNotifier {
} else { } else {
return doctorProfile; return doctorProfile;
} }
} }
setDoctorProfile(DoctorProfileModel doctorProfile){
sharedPref.setObj(DOCTOR_PROFILE, doctorProfile);
doctorProfile = doctorProfile;
}
} }

@ -1,14 +1,19 @@
import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/client/base_app_client.dart';
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/core/service/authentication_service.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import '../../locator.dart';
enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED } enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED }
class DoctorProfileViewModel extends BaseViewModel { class DoctorProfileViewModel extends BaseViewModel {
List<ClinicModel> doctorsClinicList = []; List<ClinicModel> doctorsClinicList = [];
AuthenticationService _authService = locator<AuthenticationService>();
String selectedClinicName; String selectedClinicName;
bool isLogin = false; bool isLogin = false;

@ -21,7 +21,7 @@ class RootPage extends StatelessWidget {
); );
break; break;
case APP_STATUS.UNAUTHENTICATED: case APP_STATUS.UNAUTHENTICATED:
return Loginsreen(); return LoginScreen();
break; break;
case APP_STATUS.AUTHENTICATED: case APP_STATUS.AUTHENTICATED:
return LandingPage(); return LandingPage();

@ -64,7 +64,7 @@ const String RADIOLOGY_PATIENT = 'radiology-patient';
var routes = { var routes = {
ROOT: (_) => RootPage(), ROOT: (_) => RootPage(),
HOME: (_) => LandingPage(), HOME: (_) => LandingPage(),
LOGIN: (_) => Loginsreen(), LOGIN: (_) => LoginScreen(),
VERIFICATION_METHODS: (_) => VerificationMethodsScreen(), VERIFICATION_METHODS: (_) => VerificationMethodsScreen(),
PATIENTS_PROFILE: (_) => PatientProfileScreen(), PATIENTS_PROFILE: (_) => PatientProfileScreen(),
LAB_RESULT: (_) => LabsHomePage(), LAB_RESULT: (_) => LabsHomePage(),

@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/config.dart';
@ -9,7 +8,6 @@ import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_m
import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/service/authentication_service.dart';
import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/models/doctor/user_model.dart';
import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart'; import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/helpers.dart';
@ -24,20 +22,18 @@ import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../../lookups/auth_lookup.dart';
import '../../util/dr_app_shared_pref.dart'; import '../../util/dr_app_shared_pref.dart';
import '../../widgets/auth/auth_header.dart';
import '../../widgets/shared/app_scaffold_widget.dart'; import '../../widgets/shared/app_scaffold_widget.dart';
//TODO Elham remove it //TODO Elham remove it
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
//TODO Elham change the name
class Loginsreen extends StatefulWidget { class LoginScreen extends StatefulWidget {
@override @override
_LoginsreenState createState() => _LoginsreenState(); _LoginScreenState createState() => _LoginScreenState();
} }
class _LoginsreenState extends State<Loginsreen> { class _LoginScreenState extends State<LoginScreen> {
String platformImei; String platformImei;
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
bool _isLoading = true; bool _isLoading = true;
@ -50,9 +46,7 @@ class _LoginsreenState extends State<Loginsreen> {
List<GetHospitalsResponseModel> projectsList = []; List<GetHospitalsResponseModel> projectsList = [];
FocusNode focusPass = FocusNode(); FocusNode focusPass = FocusNode();
FocusNode focusProject = FocusNode(); FocusNode focusProject = FocusNode();
// HospitalViewModel hospitalViewModel;
//TODO Elham to change it ti UserModel
var userInfo = UserModel();
@override @override
void initState() { void initState() {
@ -99,11 +93,7 @@ class _LoginsreenState extends State<Loginsreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
projectViewModel = Provider.of<ProjectViewModel>(context); projectViewModel = Provider.of<ProjectViewModel>(context);
return BaseView<AuthenticationViewModel>( return BaseView<AuthenticationViewModel>(
//TODO Elham remove it
onModelReady: (model) => {},
builder: (_, model, w) => builder: (_, model, w) =>
AppScaffold( AppScaffold(
baseViewModel: model, baseViewModel: model,
@ -123,7 +113,71 @@ class _LoginsreenState extends State<Loginsreen> {
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.start, CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
AuthHeader(loginType.knownUser), //TODO Use App Text rather than text
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment
.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment
.start,
children: <Widget>[
SizedBox(
height: 30,
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment
.start, children: [
SizedBox(
height: 10,
),
Text(
TranslationBase
.of(context)
.welcomeTo,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight
.w600,
fontFamily: 'Poppins'),
),
Text(
TranslationBase
.of(context)
.drSulaimanAlHabib,
style: TextStyle(
fontWeight: FontWeight
.w800,
fontSize: SizeConfig
.isMobile
? 24
: SizeConfig
.realScreenWidth *
0.029,
fontFamily: 'Poppins'),
),
Text(
"Doctor App",
style: TextStyle(
fontSize:
SizeConfig.isMobile
? 16
: SizeConfig
.realScreenWidth *
0.030,
fontWeight: FontWeight
.w800,
color: HexColor(
'#B8382C')),
),
]),
],
)),
SizedBox( SizedBox(
height: 40, height: 40,
), ),
@ -203,7 +257,7 @@ class _LoginsreenState extends State<Loginsreen> {
onSaved: (value) { onSaved: (value) {
if (value != if (value !=
null) setState(() { null) setState(() {
userInfo model.userInfo
.userID = .userID =
value value
.trim(); .trim();
@ -212,7 +266,7 @@ class _LoginsreenState extends State<Loginsreen> {
onChanged: (value) { onChanged: (value) {
if (value != null) if (value != null)
setState(() { setState(() {
userInfo model.userInfo
.userID = .userID =
value value
.trim(); .trim();
@ -276,7 +330,7 @@ class _LoginsreenState extends State<Loginsreen> {
if (value != if (value !=
null) null)
setState(() { setState(() {
userInfo model.userInfo
.password = .password =
value; value;
}); });
@ -286,7 +340,7 @@ class _LoginsreenState extends State<Loginsreen> {
if (value != if (value !=
null) null)
setState(() { setState(() {
userInfo model.userInfo
.password = .password =
value; value;
}); });
@ -300,11 +354,12 @@ class _LoginsreenState extends State<Loginsreen> {
context, context,
projectsList, projectsList,
'facilityName', 'facilityName',
onSelectProject); onSelectProject,
model);
}, },
onTap: () { onTap: () {
this.getProjects( this.getProjects(
userInfo model.userInfo
.userID, model); .userID, model);
}, },
) )
@ -352,7 +407,8 @@ class _LoginsreenState extends State<Loginsreen> {
context, context,
projectsList, projectsList,
'facilityName', 'facilityName',
onSelectProject); onSelectProject,
model);
}, },
validator: ( validator: (
value) { value) {
@ -424,9 +480,10 @@ class _LoginsreenState extends State<Loginsreen> {
.login, .login,
color: HexColor( color: HexColor(
'#D02127'), '#D02127'),
disabled: userInfo disabled: model.userInfo
.userID == null || .userID == null ||
userInfo.password == model.userInfo
.password ==
null, null,
fontWeight: FontWeight fontWeight: FontWeight
.bold, .bold,
@ -445,7 +502,7 @@ class _LoginsreenState extends State<Loginsreen> {
]) ])
: Center(child: AppLoaderWidget()), : Center(child: AppLoaderWidget()),
), ),
)); ), );
} }
SizedBox buildSizedBox() { SizedBox buildSizedBox() {
@ -459,44 +516,28 @@ class _LoginsreenState extends State<Loginsreen> {
if (loginFormKey.currentState.validate()) { if (loginFormKey.currentState.validate()) {
loginFormKey.currentState.save(); loginFormKey.currentState.save();
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
sharedPref.setInt(PROJECT_ID, userInfo.projectID); await model.login(model.userInfo);
//TODO Elham move the sharedPref to view model
await model.login(userInfo);
if (model.state == ViewState.ErrorLocal) { if (model.state == ViewState.ErrorLocal) {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
Helpers.showErrorToast(model.error); Helpers.showErrorToast(model.error);
} else { } else {
saveObjToString(LOGGED_IN_USER, model.loginInfo);
sharedPref.remove(LAST_LOGIN_USER);
sharedPref.setString(TOKEN, model.loginInfo.logInTokenID);
//TODO Elham move the sharedPref to view model
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
Navigator.of(context).pushReplacement( Navigator.of(context).pushReplacement(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) => VerificationMethodsScreen( builder: (BuildContext context) =>
password: userInfo.password, VerificationMethodsScreen(
password: model.userInfo.password,
), ),
), ),
); );
} }
} }
} }
//TODO Elham to it view model
Future<void> setSharedPref(key, value) async {
sharedPref.setString(key, value).then((success) {
});
}
//TODO Elham to it view model
saveObjToString(String key, value) async {
sharedPref.setObj(key, value);
}
onSelectProject(index) { onSelectProject(index, AuthenticationViewModel model) {
setState(() { setState(() {
userInfo.projectID = projectsList[index].facilityId; model.userInfo.projectID = projectsList[index].facilityId;
projectIdController.text = projectsList[index].facilityName; projectIdController.text = projectsList[index].facilityName;
}); });
@ -510,7 +551,7 @@ class _LoginsreenState extends State<Loginsreen> {
if(model.state == ViewState.Idle) { if(model.state == ViewState.Idle) {
projectsList = model.hospitals; projectsList = model.hospitals;
setState(() { setState(() {
userInfo.projectID = projectsList[0].facilityId; model.userInfo.projectID = projectsList[0].facilityId;
projectIdController.text = projectsList[0].facilityName; projectIdController.text = projectsList[0].facilityName;
}); });
} }

@ -5,12 +5,8 @@ import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/date-utils.dart'; import 'package:doctor_app_flutter/util/date-utils.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/auth/sms-popup.dart'; import 'package:doctor_app_flutter/widgets/auth/sms-popup.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
@ -19,9 +15,7 @@ import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dar
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:hexcolor/hexcolor.dart';
import 'package:local_auth/auth_strings.dart';
import 'package:local_auth/local_auth.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../../config/size_config.dart'; import '../../config/size_config.dart';
@ -30,17 +24,15 @@ import '../../landing_page.dart';
import '../../routes.dart'; import '../../routes.dart';
import '../../util/dr_app_shared_pref.dart'; import '../../util/dr_app_shared_pref.dart';
import '../../util/helpers.dart'; import '../../util/helpers.dart';
import '../../widgets/auth/method_card.dart'; import '../../widgets/auth/verification_methods_list.dart';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
Helpers helpers = Helpers(); Helpers helpers = Helpers();
class VerificationMethodsScreen extends StatefulWidget { class VerificationMethodsScreen extends StatefulWidget {
VerificationMethodsScreen({this.changeLoadingState, this.password}); VerificationMethodsScreen({this.password});
final password; final password;
//TODO Elham remove this fun
final Function changeLoadingState;
@override @override
_VerificationMethodsScreenState createState() => _VerificationMethodsScreenState(); _VerificationMethodsScreenState createState() => _VerificationMethodsScreenState();
@ -51,31 +43,11 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
ProjectViewModel projectsProvider; ProjectViewModel projectsProvider;
bool isMoreOption = false; bool isMoreOption = false;
bool onlySMSBox = false; bool onlySMSBox = false;
var loginTokenID;
DoctorProfileViewModel doctorProfileViewModel; DoctorProfileViewModel doctorProfileViewModel;
bool authenticated;
AuthMethodTypes fingerPrintBefore; AuthMethodTypes fingerPrintBefore;
AuthMethodTypes selectedOption; AuthMethodTypes selectedOption;
AuthenticationViewModel model; AuthenticationViewModel model;
final LocalAuthentication auth = LocalAuthentication();
//TODO Elham remove this fun
@override
void initState() {
super.initState();
}
//TODO Elham remove this fun
@override
void didChangeDependencies() async{
super.didChangeDependencies();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
doctorProfileViewModel = Provider.of<DoctorProfileViewModel>(context); doctorProfileViewModel = Provider.of<DoctorProfileViewModel>(context);
@ -93,7 +65,6 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
child: FractionallySizedBox( child: FractionallySizedBox(
child: Container( child: Container(
margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0),
height: SizeConfig.realScreenHeight * .95, height: SizeConfig.realScreenHeight * .95,
width: SizeConfig.realScreenWidth, width: SizeConfig.realScreenWidth,
child: Column( child: Column(
@ -102,7 +73,6 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
children: <Widget>[ children: <Widget>[
Container( Container(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
SizedBox( SizedBox(
height: 100, height: 100,
@ -146,54 +116,61 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
style: TextStyle( style: TextStyle(
fontFamily: 'Poppins', fontFamily: 'Poppins',
fontWeight: fontWeight:
FontWeight.w800, FontWeight
fontSize: 14), .w800,
), fontSize: 14),
subtitle: AppText( ),
model.getType( subtitle: AppText(
model.user.logInTypeID, model.getType(
context), model.user
fontSize: 14, .logInTypeID,
))), context),
Flexible( fontSize: 14,
flex: 2, ))),
child: ListTile( Flexible(
title: AppText( flex: 2,
model.user.editedOn != null child: ListTile(
? model.getDate( title: AppText(
DateUtils model.user.editedOn !=
.convertStringToDate( null
model.user ? DateUtils.getDayMonthYearDateFormatted(
.editedOn)) DateUtils.convertStringToDate(
: model.user.createdOn != null model.user
? model .editedOn))
.getDate(DateUtils : model.user.createdOn !=
.convertStringToDate( null
model.user.createdOn)) ? DateUtils.getDayMonthYearDateFormatted(
: '--', DateUtils.convertStringToDate(model
textAlign: TextAlign.right, .user
fontSize: 14, .createdOn))
fontWeight: FontWeight.w800, : '--',
), textAlign:
subtitle: AppText( TextAlign.right,
model.user.editedOn != null fontSize: 14,
? model.getTime( fontWeight:
DateUtils FontWeight.w800,
.convertStringToDate( ),
model.user subtitle: AppText(
.editedOn)) model.user.editedOn !=
: model.user.createdOn != null null
? model ? DateUtils.getHour(
.getTime(DateUtils DateUtils.convertStringToDate(
.convertStringToDate( model.user
model.user.createdOn)) .editedOn))
: '--', : model.user.createdOn !=
textAlign: TextAlign.right, null
fontSize: 14, ? DateUtils.getHour(
), DateUtils.convertStringToDate(model
)) .user
], .createdOn))
)), : '--',
textAlign:
TextAlign.right,
fontSize: 14,
),
))
],
)),
], ],
) )
: Column( : Column(
@ -228,43 +205,39 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: InkWell( child: InkWell(
onTap: () => { onTap: () =>
// TODO check this logic it seem it will create bug to us {
authenticateUser(AuthMethodTypes.Fingerprint, true) // TODO check this logic it seem it will create bug to us
}, authenticateUser(
child: MethodCard( AuthMethodTypes
authMethodType: model.user .Fingerprint, true)
.logInTypeID == },
4 child: VerificationMethodsList(
? AuthMethodTypes.FaceID model: model,
: model.user.logInTypeID == 2 authMethodType: SelectedAuthMethodTypesService
? AuthMethodTypes .getMethodsTypeService(
.WhatsApp model.user
: model.user.logInTypeID == .logInTypeID),
3
? AuthMethodTypes
.Fingerprint
: AuthMethodTypes
.SMS,
authenticateUser: authenticateUser:
(AuthMethodTypes (AuthMethodTypes
authMethodType, authMethodType,
isActive) => isActive) =>
authenticateUser( authenticateUser(
authMethodType, authMethodType,
isActive), isActive),
)), )),
), ),
Expanded( Expanded(
child: MethodCard( child: VerificationMethodsList(
authMethodType: model: model,
authMethodType:
AuthMethodTypes.MoreOptions, AuthMethodTypes.MoreOptions,
onShowMore: () { onShowMore: () {
setState(() { setState(() {
isMoreOption = true; isMoreOption = true;
}); });
}, },
)) ))
]), ]),
]) ])
: Column( : Column(
@ -277,29 +250,31 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
MainAxisAlignment.center, MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: MethodCard( child: VerificationMethodsList(
authMethodType: model: model,
authMethodType:
AuthMethodTypes.Fingerprint, AuthMethodTypes.Fingerprint,
authenticateUser: authenticateUser:
(AuthMethodTypes (AuthMethodTypes
authMethodType, authMethodType,
isActive) => isActive) =>
authenticateUser( authenticateUser(
authMethodType, authMethodType,
isActive), isActive),
)), )),
Expanded( Expanded(
child: MethodCard( child: VerificationMethodsList(
authMethodType: model: model,
authMethodType:
AuthMethodTypes.FaceID, AuthMethodTypes.FaceID,
authenticateUser: authenticateUser:
(AuthMethodTypes (AuthMethodTypes
authMethodType, authMethodType,
isActive) => isActive) =>
authenticateUser( authenticateUser(
authMethodType, authMethodType,
isActive), isActive),
)) ))
], ],
) )
: SizedBox(), : SizedBox(),
@ -308,60 +283,79 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
MainAxisAlignment.center, MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: MethodCard( child: VerificationMethodsList(
authMethodType: AuthMethodTypes.SMS, model: model,
authenticateUser: authMethodType: AuthMethodTypes
(AuthMethodTypes authMethodType, .SMS,
isActive) => authenticateUser:
(
AuthMethodTypes authMethodType,
isActive) =>
authenticateUser( authenticateUser(
authMethodType, isActive), authMethodType, isActive),
)), )),
Expanded( Expanded(
child: MethodCard( child: VerificationMethodsList(
authMethodType: model: model,
authMethodType:
AuthMethodTypes.WhatsApp, AuthMethodTypes.WhatsApp,
authenticateUser: authenticateUser:
(AuthMethodTypes authMethodType, (
isActive) => AuthMethodTypes authMethodType,
isActive) =>
authenticateUser( authenticateUser(
authMethodType, isActive), authMethodType, isActive),
)) ))
], ],
), ),
]), ]),
// ) // )
], ],
), ),
), ),
//TODO Elham move it to bottom sheet
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
model.user != null
? Row(
children: <Widget>[
Expanded(
child: AppButton(
title: TranslationBase.of(context)
.useAnotherAccount,
color: Colors.red[700],
onPressed: () {
Navigator.of(context).pushNamed(LOGIN);
},
)),
],
)
: SizedBox(),
],
),
], ],
), ),
), ),
), ),
), ),
), ),
)); bottomSheet: model.user == null ? SizedBox(height: 0,) : Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(0.0),
),
border: Border.all(
color: HexColor('#707070'),
width: 0),
),
height: 90,
width: double.infinity,
child: Center(
child: FractionallySizedBox(
widthFactor: 0.9,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
AppButton(
title: TranslationBase
.of(context)
.useAnotherAccount,
color: Colors.red[700],
onPressed: () {
Navigator.of(context).pushNamed(LOGIN);
},
),
SizedBox(height: 25,)
],
),
),
),),
)
);
} }
sendActivationCodeByOtpNotificationType( sendActivationCodeByOtpNotificationType(
@ -391,8 +385,6 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async { sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
await model await model
.sendActivationCodeVerificationScreen(authMethodType); .sendActivationCodeVerificationScreen(authMethodType);
@ -466,32 +458,21 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
}, },
() => () =>
{ {
widget.changeLoadingState(false),
print('Faild..'), print('Faild..'),
}, },
).displayDialog(context); ).displayDialog(context);
} }
//TODO Elham move it to view model
loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes,
isActive) async { isActive) async {
if (isActive) { if (isActive) {
const iosStrings = const IOSAuthMessages( await model.showIOSAuthMessages();
cancelButton: 'cancel',
goToSettingsButton: 'settings',
goToSettingsDescription: 'Please set up your Touch ID.',
lockOut: 'Please reenable your Touch ID');
try {
authenticated = await auth.authenticateWithBiometrics(
localizedReason: 'Scan your fingerprint to authenticate',
useErrorDialogs: true,
stickyAuth: true,
iOSAuthStrings: iosStrings);
} on PlatformException catch (e) {
DrAppToastMsg.showErrorToast(e.toString());
}
if (!mounted) return; if (!mounted) return;
if (model.user != null && (model.user.logInTypeID == 3 || model.user.logInTypeID == 4)) { if (model.user != null &&
(SelectedAuthMethodTypesService.getMethodsTypeService(
model.user.logInTypeID) ==
AuthMethodTypes.Fingerprint ||
SelectedAuthMethodTypesService.getMethodsTypeService(
model.user.logInTypeID) == AuthMethodTypes.FaceID)) {
this.sendActivationCode(authMethodTypes); this.sendActivationCode(authMethodTypes);
} else { } else {
setState(() { setState(() {
@ -502,64 +483,30 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
} }
checkActivationCode({value}) async { checkActivationCode({value}) async {
await model.checkActivationCodeForDoctorApp(activationCode: value);
await model.checkActivationCodeForDoctorApp(activationCode:value );
if (model.state == ViewState.ErrorLocal) { if (model.state == ViewState.ErrorLocal) {
Navigator.pop(context); Navigator.pop(context);
Helpers.showErrorToast(model.error); Helpers.showErrorToast(model.error);
} else { } else {
sharedPref.setString( await model.onCheckActivationCodeSuccess();
TOKEN, model.checkActivationCodeForDoctorAppRes.authenticationTokenID); navigateToLandingPage();
//TODO Elham check the logic
if (model.checkActivationCodeForDoctorAppRes.listDoctorsClinic.isNotEmpty) {
loginProcessCompleted(model.checkActivationCodeForDoctorAppRes.list_DoctorProfile[0]);
sharedPref.setObj(
CLINIC_NAME,
model
.checkActivationCodeForDoctorAppRes.listDoctorsClinic);
} else {
sharedPref.setObj(
CLINIC_NAME,
model
.checkActivationCodeForDoctorAppRes.listDoctorsClinic);
ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes.listDoctorsClinic[0].toJson());
getDocProfiles(clinic);
}
} }
} }
//TODO Elham move it to view model
loginProcessCompleted(Map<String, dynamic> profile) {
var doctor = DoctorProfileModel.fromJson(profile);
doctorProfileViewModel.setDoctorProfile(doctor);
sharedPref.setObj(DOCTOR_PROFILE, profile);
projectsProvider.isLogin = true;
Navigator.pushAndRemoveUntil( navigateToLandingPage() {
context, if (model.state == ViewState.ErrorLocal) {
FadePage( Helpers.showErrorToast(model.error);
page: LandingPage(), } else {
), projectsProvider.isLogin = true;
(r) => false);
} Navigator.pushAndRemoveUntil(
//TODO Elham move it to view model context,
getDocProfiles(ClinicModel clinicInfo) { FadePage(
ProfileReqModel docInfo = new ProfileReqModel( page: LandingPage(),
doctorID: clinicInfo.doctorID, ), (r) => false);
clinicID: clinicInfo.clinicID, }
license: true,
projectID: clinicInfo.projectID,
tokenID: '',
languageID: 2);
doctorProfileViewModel.getDocProfiles(docInfo.toJson()).then((res) {
if (res['MessageStatus'] == 1) {
loginProcessCompleted(res['DoctorProfileList'][0]);
} else {
Helpers.showErrorToast(res['ErrorEndUserMessage']);
}
}).catchError((err) {
Helpers.showErrorToast(err);
});
} }
} }

@ -1,6 +1,8 @@
import 'package:connectivity/connectivity.dart'; import 'package:connectivity/connectivity.dart';
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/core/model/hospitals/get_hospitals_response_model.dart';
import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/models/doctor/list_doctor_working_hours_table_model.dart'; import 'package:doctor_app_flutter/models/doctor/list_doctor_working_hours_table_model.dart';
import 'package:doctor_app_flutter/screens/auth/login_screen.dart'; import 'package:doctor_app_flutter/screens/auth/login_screen.dart';
@ -22,7 +24,7 @@ class Helpers {
static int cupertinoPickerIndex = 0; static int cupertinoPickerIndex = 0;
get currentLanguage => null; get currentLanguage => null;
static showCupertinoPicker(context, items, decKey, onSelectFun) { static showCupertinoPicker(context, List<GetHospitalsResponseModel> items, decKey, onSelectFun, AuthenticationViewModel model) {
showModalBottomSheet( showModalBottomSheet(
isDismissible: false, isDismissible: false,
context: context, context: context,
@ -53,7 +55,7 @@ class Helpers {
), ),
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
onSelectFun(cupertinoPickerIndex); onSelectFun(cupertinoPickerIndex, model);
}, },
) )
], ],
@ -63,7 +65,7 @@ class Helpers {
height: SizeConfig.realScreenHeight * 0.3, height: SizeConfig.realScreenHeight * 0.3,
color: Color(0xfff7f7f7), color: Color(0xfff7f7f7),
child: child:
buildPickerItems(context, items, decKey, onSelectFun)) buildPickerItems(context, items, decKey, onSelectFun, model))
], ],
), ),
); );
@ -73,14 +75,14 @@ class Helpers {
static TextStyle textStyle(context) => static TextStyle textStyle(context) =>
TextStyle(color: Theme.of(context).primaryColor); TextStyle(color: Theme.of(context).primaryColor);
static buildPickerItems(context, List items, decKey, onSelectFun) { static buildPickerItems(context, List<GetHospitalsResponseModel> items, decKey, onSelectFun, model) {
return CupertinoPicker( return CupertinoPicker(
magnification: 1.5, magnification: 1.5,
scrollController: scrollController:
FixedExtentScrollController(initialItem: cupertinoPickerIndex), FixedExtentScrollController(initialItem: cupertinoPickerIndex),
children: items.map((item) { children: items.map((item) {
return Text( return Text(
'${item["$decKey"]}', '${item.facilityName}',
style: TextStyle(fontSize: SizeConfig.textMultiplier * 2), style: TextStyle(fontSize: SizeConfig.textMultiplier * 2),
); );
}).toList(), }).toList(),
@ -151,7 +153,7 @@ class Helpers {
Navigator.pushAndRemoveUntil( Navigator.pushAndRemoveUntil(
AppGlobal.CONTEX, AppGlobal.CONTEX,
FadePage( FadePage(
page: Loginsreen(), page: LoginScreen(),
), ),
(r) => false); (r) => false);
} }

@ -1,113 +0,0 @@
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:hexcolor/hexcolor.dart';
import '../../config/size_config.dart';
import '../../lookups/auth_lookup.dart';
//TODO Elham delete this widget
class AuthHeader extends StatelessWidget {
var userType;
AuthHeader(this.userType);
@override
Widget build(BuildContext context) {
var screen = Container(
margin: SizeConfig.isMobile
? null
: EdgeInsetsDirectional.fromSTEB(SizeConfig.realScreenWidth * 0.30,
SizeConfig.realScreenWidth * 0.1, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 30,
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: SizeConfig.isMobile
? <Widget>[
SizedBox(
height: 10,
),
buildWelText(context),
buildDrSulText(context),
]
: <Widget>[
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
buildWelText(context),
buildDrSulText(context),
],
),
],
),
buildDrAppContainer(context)
],
));
return screen;
}
Container buildDrAppContainer(BuildContext context) {
if (userType == loginType.changePassword ||
userType == loginType.verifyPassword ||
userType == loginType.verificationMethods) {
return Container();
}
return Container(
child: Text(
"Doctor App",
style: TextStyle(
fontSize:
SizeConfig.isMobile ? 16 : SizeConfig.realScreenWidth * 0.030,
fontWeight: FontWeight.w800,
color: HexColor('#B8382C')),
),
);
}
Text buildDrSulText(BuildContext context) {
if (userType == loginType.changePassword ||
userType == loginType.verifyPassword ||
userType == loginType.verificationMethods) {
return Text('');
}
return Text(
TranslationBase.of(context).drSulaimanAlHabib,
style: TextStyle(
fontWeight: FontWeight.w800,
fontSize:
SizeConfig.isMobile ? 24 : SizeConfig.realScreenWidth * 0.029,
fontFamily: 'Poppins'),
);
}
Widget buildWelText(BuildContext context) {
String text = TranslationBase.of(context).welcomeTo;
if (userType == loginType.unknownUser) {
text = TranslationBase.of(context).welcomeBackTo;
}
if (userType == loginType.changePassword ||
userType == loginType.verifyPassword ||
userType == loginType.verificationMethods) {
return Text('');
}
return AppText(
text,
// style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
);
}
}

@ -1,244 +0,0 @@
import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:local_auth/local_auth.dart';
import 'package:provider/provider.dart';
class MethodCard extends StatefulWidget {
final AuthMethodTypes authMethodType;
final Function ( AuthMethodTypes type, bool isActive) authenticateUser;
final Function onShowMore;
const MethodCard({Key key, this.authMethodType, this.authenticateUser, this.onShowMore}) : super(key: key);
@override
_MethodCardState createState() => _MethodCardState();
}
class _MethodCardState extends State<MethodCard> {
//TODO Elham change it to list Enum
var _availableBiometrics;
final LocalAuthentication auth = LocalAuthentication();
ProjectViewModel projectsProvider;
@override
void initState() {
super.initState();
_getAvailableBiometrics();
}
bool checkIfBiometricAvailable(BiometricType biometricType) {
bool isAvailable = false;
if (_availableBiometrics != null) {
for (var i = 0; i < _availableBiometrics.length; i++) {
if (biometricType == _availableBiometrics[i]) isAvailable = true;
}
}
return isAvailable;
}
Future<void> _getAvailableBiometrics() async {
var availableBiometrics;
try {
availableBiometrics = await auth.getAvailableBiometrics();
} on PlatformException catch (e) {
print(e);
}
if (!mounted) return;
setState(() {
_availableBiometrics = availableBiometrics;
});
}
@override
Widget build(BuildContext context) {
projectsProvider = Provider.of<ProjectViewModel>(context);
switch (widget.authMethodType) {
case AuthMethodTypes.WhatsApp:
return InkWell(
onTap: () => {widget.authenticateUser(AuthMethodTypes.WhatsApp, true)},
//TODO Elham change it to widget
child: Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Padding(
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: [
Image.asset(
'assets/images/verify-whtsapp.png',
height: 60,
width: 60,
),
],
),
SizedBox(
height: 20,
),
AppText(
TranslationBase.of(context).verifyWhatsApp,
fontSize: 14,
fontWeight: FontWeight.w600,
)
],
),
)));
break;
case AuthMethodTypes.SMS:
return InkWell(
onTap: () => {widget.authenticateUser(AuthMethodTypes.SMS, true)},
child: Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Padding(
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.asset(
'assets/images/verify-sms.png',
height: 60,
width: 60,
),
SizedBox(
height: 20,
),
AppText(
TranslationBase.of(context).verifySMS,
fontSize: 14,
fontWeight: FontWeight.w600,
)
],
),
)));
break;
case AuthMethodTypes.Fingerprint:
return InkWell(
onTap: () => {
if (checkIfBiometricAvailable(BiometricType.fingerprint))
{widget.authenticateUser(AuthMethodTypes.Fingerprint, true)}
},
child: Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Padding(
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.asset(
'assets/images/verification_fingerprint_icon.png',
height: 60,
width: 60,
),
SizedBox(
height: 20,
),
AppText(
TranslationBase.of(context).verifyFingerprint,
fontSize: 14,
fontWeight: FontWeight.w600,
)
],
),
)));
break;
case AuthMethodTypes.FaceID:
return InkWell(
onTap: () {
if (checkIfBiometricAvailable(BiometricType.face)) {
widget.authenticateUser(AuthMethodTypes.FaceID, true);
}
},
child:
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
margin: EdgeInsets.all(10),
child: Padding(
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.asset(
'assets/images/verification_faceid_icon.png',
height: 60,
width: 60,
),
SizedBox(
height: 20,
),
AppText(
TranslationBase.of(context).verifyFaceID,
fontSize: 14,
fontWeight: FontWeight.w600,
)
],
),
)));
break;
default:
return InkWell(
onTap: widget.onShowMore,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Padding(
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.asset(
'assets/images/login/more_icon.png',
height: 60,
width: 60,
),
projectsProvider.isArabic
? SizedBox(
height: 20,
)
: SizedBox(
height: 10,
),
AppText(
TranslationBase.of(context).moreVerification,
fontSize: 14,
fontWeight: FontWeight.w600,
)
],
),
)));
};
}
}

@ -0,0 +1,53 @@
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';
class MethodTypeCard extends StatelessWidget {
const MethodTypeCard({
Key key,
this.assetPath,
this.onTap,
this.label,
}) : super(key: key);
final String assetPath;
final Function onTap;
final String label;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Padding(
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: [
Image.asset(
assetPath,
height: 60,
width: 60,
),
],
),
SizedBox(
height: 20,
),
AppText(
label,
fontSize: 14,
fontWeight: FontWeight.w600,
)
],
),
)),
);
}
}

@ -0,0 +1,87 @@
import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/auth/method_type_card.dart';
import 'package:flutter/material.dart';
import 'package:local_auth/local_auth.dart';
import 'package:provider/provider.dart';
class VerificationMethodsList extends StatefulWidget {
final AuthMethodTypes authMethodType;
final Function(AuthMethodTypes type, bool isActive) authenticateUser;
final Function onShowMore;
final AuthenticationViewModel model;
const VerificationMethodsList(
{Key key,
this.authMethodType,
this.authenticateUser,
this.onShowMore,
this.model})
: super(key: key);
@override
_VerificationMethodsListState createState() =>
_VerificationMethodsListState();
}
class _VerificationMethodsListState extends State<VerificationMethodsList> {
final LocalAuthentication auth = LocalAuthentication();
ProjectViewModel projectsProvider;
@override
Widget build(BuildContext context) {
projectsProvider = Provider.of<ProjectViewModel>(context);
switch (widget.authMethodType) {
case AuthMethodTypes.WhatsApp:
return MethodTypeCard(
assetPath: 'assets/images/verify-whtsapp.png',
onTap: () =>
{widget.authenticateUser(AuthMethodTypes.WhatsApp, true)},
label: TranslationBase.of(context).verifyWhatsApp,
);
break;
case AuthMethodTypes.SMS:
return MethodTypeCard(
assetPath: "assets/images/verify-sms.png",
onTap: () => {widget.authenticateUser(AuthMethodTypes.SMS, true)},
label: TranslationBase.of(context).verifySMS,
);
break;
case AuthMethodTypes.Fingerprint:
return MethodTypeCard(
assetPath: 'assets/images/verification_fingerprint_icon.png',
onTap: () async {
if (await widget.model
.checkIfBiometricAvailable(BiometricType.fingerprint)) {
widget.authenticateUser(AuthMethodTypes.Fingerprint, true);
}
},
label: TranslationBase.of(context).verifyFingerprint,
);
break;
case AuthMethodTypes.FaceID:
return MethodTypeCard(
assetPath: 'assets/images/verification_faceid_icon.png',
onTap: () async {
if (await widget.model
.checkIfBiometricAvailable(BiometricType.face)) {
widget.authenticateUser(AuthMethodTypes.FaceID, true);
}
},
label: TranslationBase.of(context).verifyFaceID,
);
break;
default:
return MethodTypeCard(
assetPath: 'assets/images/login/more_icon.png',
onTap: widget.onShowMore,
label: TranslationBase.of(context).moreVerification,
);
}
}
}
Loading…
Cancel
Save