add UNVERIFIED status

auth_refactor
Elham Rababah 5 years ago
parent fd9f93a936
commit 2e71706cab

@ -35,6 +35,9 @@ class AuthenticationService extends BaseService {
List<DoctorProfileModel> _doctorProfilesList = []; List<DoctorProfileModel> _doctorProfilesList = [];
List<DoctorProfileModel> get doctorProfilesList => _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,

@ -1,3 +1,5 @@
import 'dart:io';
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/enum/auth_method_types.dart'; import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
@ -20,8 +22,10 @@ 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 'package:doctor_app_flutter/models/doctor/profile_req_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/screens/auth/verification_methods_screen.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.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:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:local_auth/auth_strings.dart'; import 'package:local_auth/auth_strings.dart';
import 'package:local_auth/local_auth.dart'; import 'package:local_auth/local_auth.dart';
@ -29,6 +33,8 @@ import 'package:provider/provider.dart';
import 'doctor_profile_view_model.dart'; import 'doctor_profile_view_model.dart';
enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED, UNVERIFIED }
class AuthenticationViewModel extends BaseViewModel { class AuthenticationViewModel extends BaseViewModel {
AuthenticationService _authService = locator<AuthenticationService>(); AuthenticationService _authService = locator<AuthenticationService>();
HospitalsService _hospitalsService = locator<HospitalsService>(); HospitalsService _hospitalsService = locator<HospitalsService>();
@ -38,7 +44,9 @@ class AuthenticationViewModel extends BaseViewModel {
List<GetHospitalsResponseModel> get hospitals => _hospitalsService.hospitals; List<GetHospitalsResponseModel> get hospitals => _hospitalsService.hospitals;
NewLoginInformationModel get loginInfo => _authService.loginInfo; NewLoginInformationModel get loginInfo => _authService.loginInfo;
List<DoctorProfileModel> get doctorProfilesList => _authService.doctorProfilesList; List<DoctorProfileModel> get doctorProfilesList => _authService.doctorProfilesList;
SendActivationCodeForDoctorAppResponseModel SendActivationCodeForDoctorAppResponseModel
get activationCodeVerificationScreenRes => get activationCodeVerificationScreenRes =>
_authService.activationCodeVerificationScreenRes; _authService.activationCodeVerificationScreenRes;
@ -57,7 +65,14 @@ class AuthenticationViewModel extends BaseViewModel {
UserModel userInfo = UserModel(); UserModel userInfo = UserModel();
final LocalAuthentication auth = LocalAuthentication(); final LocalAuthentication auth = LocalAuthentication();
List<BiometricType> _availableBiometrics; List<BiometricType> _availableBiometrics;
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
bool isLogin = false;
bool unverified = false;
AuthenticationViewModel({bool checkDeviceInfo = false}) {
getDeviceInfoFromFirebase();
}
Future selectDeviceImei(imei) async { Future selectDeviceImei(imei) async {
setState(ViewState.Busy); setState(ViewState.Busy);
@ -70,7 +85,6 @@ class AuthenticationViewModel extends BaseViewModel {
} }
Future insertDeviceImei() async { Future insertDeviceImei() async {
var loggedIn = await sharedPref.getObj(LOGGED_IN_USER); var loggedIn = await sharedPref.getObj(LOGGED_IN_USER);
var user = await sharedPref.getObj(LAST_LOGIN_USER); var user = await sharedPref.getObj(LAST_LOGIN_USER);
if (user != null) { if (user != null) {
@ -116,6 +130,7 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.ErrorLocal); setState(ViewState.ErrorLocal);
} else { } else {
sharedPref.setInt(PROJECT_ID, userInfo.projectID); sharedPref.setInt(PROJECT_ID, userInfo.projectID);
loggedUser = loginInfo;
saveObjToString(LOGGED_IN_USER, loginInfo); saveObjToString(LOGGED_IN_USER, loginInfo);
sharedPref.remove(LAST_LOGIN_USER); sharedPref.remove(LAST_LOGIN_USER);
sharedPref.setString(TOKEN, loginInfo.logInTokenID); sharedPref.setString(TOKEN, loginInfo.logInTokenID);
@ -183,7 +198,6 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.ErrorLocal); setState(ViewState.ErrorLocal);
} else { } else {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
} }
@ -238,8 +252,7 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
setDataAfterSendActivationSuccsess( setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) {
SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) {
print("VerificationCode : " + print("VerificationCode : " +
sendActivationCodeForDoctorAppResponseModel.verificationCode); sendActivationCodeForDoctorAppResponseModel.verificationCode);
sharedPref.setString(VIDA_AUTH_TOKEN_ID, sharedPref.setString(VIDA_AUTH_TOKEN_ID,
@ -306,8 +319,6 @@ class AuthenticationViewModel extends BaseViewModel {
.isNotEmpty) { .isNotEmpty) {
localSetDoctorProfile( localSetDoctorProfile(
checkActivationCodeForDoctorAppRes.listDoctorProfile[0]); checkActivationCodeForDoctorAppRes.listDoctorProfile[0]);
} else { } else {
sharedPref.setObj( sharedPref.setObj(
CLINIC_NAME, CLINIC_NAME,
@ -338,4 +349,54 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
getDeviceInfoFromFirebase() async {
_firebaseMessaging.setAutoInitEnabled(true);
if (Platform.isIOS) {
_firebaseMessaging.requestNotificationPermissions();
}
setState(ViewState.Busy);
_firebaseMessaging.getToken().then((String token) async {
if (DEVICE_TOKEN == "") {
DEVICE_TOKEN = token;
await _authService.selectDeviceImei(DEVICE_TOKEN);
if (_authService.hasError) {
error = _authService.error;
setState(ViewState.ErrorLocal);
} else {
if (_authService.dashboardItemsList.length > 0) {
user =_authService.dashboardItemsList[0];
sharedPref.setObj(
LAST_LOGIN_USER, _authService.dashboardItemsList[0]);
this.unverified = true;
// Navigator.of(AppGlobal.CONTEX).pushReplacement(MaterialPageRoute(
// builder: (BuildContext context) => VerificationMethodsScreen(
// password: null,
// )));
}
setState(ViewState.Idle);
}
} else {
setState(ViewState.Idle);
}
});
}
APP_STATUS get stutas {
if (state == ViewState.Busy) {
return APP_STATUS.LOADING;
} else {
if (this.unverified) {
return APP_STATUS.UNVERIFIED;
} else if (this.isLogin) {
return APP_STATUS.AUTHENTICATED;
} else {
return APP_STATUS.UNAUTHENTICATED;
}
}
}
} }

@ -8,7 +8,6 @@ import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import '../../locator.dart'; import '../../locator.dart';
enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED }
class DoctorProfileViewModel extends BaseViewModel { class DoctorProfileViewModel extends BaseViewModel {
List<ClinicModel> doctorsClinicList = []; List<ClinicModel> doctorsClinicList = [];
@ -41,18 +40,6 @@ class DoctorProfileViewModel extends BaseViewModel {
} }
notifyListeners(); notifyListeners();
} }
//TODO Elham move it auth view model
APP_STATUS get stutas {
if (isLoading) {
return APP_STATUS.LOADING;
} else {
if (this.isLogin) {
return APP_STATUS.AUTHENTICATED;
} else {
return APP_STATUS.UNAUTHENTICATED;
}
}
}
Future<dynamic> getDocProfiles(docInfo, Future<dynamic> getDocProfiles(docInfo,
{bool allowChangeProfile = true}) async { {bool allowChangeProfile = true}) async {

@ -90,7 +90,6 @@ void setupLocator() {
/// View Model /// View Model
locator.registerFactory(() => DoctorReplayViewModel()); locator.registerFactory(() => DoctorReplayViewModel());
locator.registerFactory(() => AuthenticationViewModel());
locator.registerFactory(() => ScheduleViewModel()); locator.registerFactory(() => ScheduleViewModel());
locator.registerFactory(() => ReferralPatientViewModel()); locator.registerFactory(() => ReferralPatientViewModel());
locator.registerFactory(() => ReferredPatientViewModel()); locator.registerFactory(() => ReferredPatientViewModel());

@ -11,6 +11,7 @@ import 'package:provider/provider.dart';
import './config/size_config.dart'; import './config/size_config.dart';
import './routes.dart'; import './routes.dart';
import 'config/config.dart'; import 'config/config.dart';
import 'core/viewModel/authentication_view_model.dart';
import 'core/viewModel/doctor_profile_view_model.dart'; import 'core/viewModel/doctor_profile_view_model.dart';
import 'core/viewModel/hospitals_view_model.dart'; import 'core/viewModel/hospitals_view_model.dart';
import 'locator.dart'; import 'locator.dart';
@ -23,7 +24,6 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
AppGlobal.CONTEX = context; AppGlobal.CONTEX = context;
@ -33,10 +33,10 @@ class MyApp extends StatelessWidget {
SizeConfig().init(constraints, orientation); SizeConfig().init(constraints, orientation);
return MultiProvider( return MultiProvider(
providers: [ providers: [
ChangeNotifierProvider<AuthenticationViewModel>(
create: (context) => AuthenticationViewModel()),
ChangeNotifierProvider<DoctorProfileViewModel>( ChangeNotifierProvider<DoctorProfileViewModel>(
create: (context) => DoctorProfileViewModel()), create: (context) => DoctorProfileViewModel()),
// ChangeNotifierProvider<HospitalViewModel>(
// create: (context) => HospitalViewModel()),
ChangeNotifierProvider<ProjectViewModel>( ChangeNotifierProvider<ProjectViewModel>(
create: (context) => ProjectViewModel(), create: (context) => ProjectViewModel(),
), ),

@ -1,25 +1,30 @@
import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/locator.dart';
import 'package:doctor_app_flutter/screens/auth/login_screen.dart'; import 'package:doctor_app_flutter/screens/auth/login_screen.dart';
import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart';
import 'package:doctor_app_flutter/widgets/shared/app_loader_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart'; import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'core/viewModel/authentication_view_model.dart';
import 'landing_page.dart'; import 'landing_page.dart';
class RootPage extends StatelessWidget { class RootPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
DoctorProfileViewModel authProvider = Provider.of(context); AuthenticationViewModel authenticationViewModel = Provider.of(context);
// ignore: missing_return
Widget buildRoot() { Widget buildRoot() {
switch (authProvider.stutas) { switch (authenticationViewModel.stutas) {
case APP_STATUS.LOADING: case APP_STATUS.LOADING:
return Scaffold( return Scaffold(
body: Center( body: AppLoaderWidget(),
child: DrAppCircularProgressIndeicator(),
),
); );
break; break;
case APP_STATUS.UNVERIFIED:
return VerificationMethodsScreen(password: null,);
break;
case APP_STATUS.UNAUTHENTICATED: case APP_STATUS.UNAUTHENTICATED:
return LoginScreen(); return LoginScreen();
break; break;

@ -1,32 +1,20 @@
import 'dart:io';
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/config/size_config.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/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/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/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/util/helpers.dart'; import 'package:doctor_app_flutter/util/helpers.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/shared/app_loader_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
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/shared/text_fields/app_text_form_field.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart'; 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 '../../util/dr_app_shared_pref.dart';
import '../../widgets/shared/app_scaffold_widget.dart'; import '../../widgets/shared/app_scaffold_widget.dart';
//TODO Elham remove it
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
class LoginScreen extends StatefulWidget { class LoginScreen extends StatefulWidget {
@override @override
@ -35,10 +23,6 @@ class LoginScreen extends StatefulWidget {
class _LoginScreenState extends State<LoginScreen> { class _LoginScreenState extends State<LoginScreen> {
String platformImei; String platformImei;
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
bool _isLoading = true;
ProjectViewModel projectViewModel;
AuthenticationService authService = AuthenticationService();
//TODO change AppTextFormField to AppTextFormFieldCustom //TODO change AppTextFormField to AppTextFormFieldCustom
final loginFormKey = GlobalKey<FormState>(); final loginFormKey = GlobalKey<FormState>();
@ -46,72 +30,24 @@ class _LoginScreenState extends State<LoginScreen> {
List<GetHospitalsResponseModel> projectsList = []; List<GetHospitalsResponseModel> projectsList = [];
FocusNode focusPass = FocusNode(); FocusNode focusPass = FocusNode();
FocusNode focusProject = FocusNode(); FocusNode focusProject = FocusNode();
AuthenticationViewModel authenticationViewModel;
@override
void initState() {
super.initState();
//TODO Elham move it root page and the logic in the view model
_firebaseMessaging.setAutoInitEnabled(true);
if (Platform.isIOS) {
_firebaseMessaging.requestNotificationPermissions();
}
_firebaseMessaging.getToken().then((String token) async {
if (DEVICE_TOKEN == "" && projectViewModel.isLogin == false) {
DEVICE_TOKEN = token;
changeLoadingState(true);
authService.selectDeviceImei(DEVICE_TOKEN).then((value) {
print(authService.dashboardItemsList);
if (authService.dashboardItemsList.length > 0) {
sharedPref.setObj(
LAST_LOGIN_USER, authService.dashboardItemsList[0]);
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (BuildContext context) => VerificationMethodsScreen(
password: null,
)));
} else {
changeLoadingState(false);
}
});
} else {
changeLoadingState(false);
}
}).catchError((err) {
print(err);
});
}
//TODO Elham change it to GIF
void changeLoadingState(isLoading) {
setState(() {
_isLoading = isLoading;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
projectViewModel = Provider.of<ProjectViewModel>(context); authenticationViewModel = Provider.of<AuthenticationViewModel>(context);
return BaseView<AuthenticationViewModel>( return AppScaffold(
builder: (_, model, w) =>
AppScaffold(
baseViewModel: model,
isShowAppBar: false, isShowAppBar: false,
backgroundColor: HexColor('#F8F8F8'), backgroundColor: HexColor('#F8F8F8'),
body: SafeArea( body: SafeArea(
child: (_isLoading == false) child: ListView(children: <Widget>[
? ListView(children: <Widget>[
Container( Container(
margin: margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 30),
EdgeInsetsDirectional.fromSTEB(30, 0, 30, 30),
alignment: Alignment.topLeft, alignment: Alignment.topLeft,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Column( Column(
crossAxisAlignment: crossAxisAlignment: CrossAxisAlignment.start,
CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
//TODO Use App Text rather than text //TODO Use App Text rather than text
Container( Container(
@ -257,7 +193,7 @@ class _LoginScreenState extends State<LoginScreen> {
onSaved: (value) { onSaved: (value) {
if (value != if (value !=
null) setState(() { null) setState(() {
model.userInfo authenticationViewModel.userInfo
.userID = .userID =
value value
.trim(); .trim();
@ -266,14 +202,13 @@ class _LoginScreenState extends State<LoginScreen> {
onChanged: (value) { onChanged: (value) {
if (value != null) if (value != null)
setState(() { setState(() {
model.userInfo authenticationViewModel.userInfo
.userID = .userID =
value value
.trim(); .trim();
}); });
}, },
onFieldSubmitted: ( onFieldSubmitted: (_) {
_) {
focusPass focusPass
.nextFocus(); .nextFocus();
}, },
@ -330,23 +265,21 @@ class _LoginScreenState extends State<LoginScreen> {
if (value != if (value !=
null) null)
setState(() { setState(() {
model.userInfo authenticationViewModel.userInfo
.password = .password =
value; value;
}); });
}, },
onChanged: (value){ onChanged: (value){
if (value != if (value !=
null) null)
setState(() { setState(() {
model.userInfo authenticationViewModel.userInfo
.password = .password =
value; value;
}); });
}, },
onFieldSubmitted: ( onFieldSubmitted: (_) {
_) {
focusPass focusPass
.nextFocus(); .nextFocus();
Helpers Helpers
@ -355,12 +288,12 @@ class _LoginScreenState extends State<LoginScreen> {
projectsList, projectsList,
'facilityName', 'facilityName',
onSelectProject, onSelectProject,
model); authenticationViewModel);
}, },
onTap: () { onTap: () {
this.getProjects( this.getProjects(
model.userInfo authenticationViewModel.userInfo
.userID, model); .userID);
}, },
) )
])), ])),
@ -408,10 +341,9 @@ class _LoginScreenState extends State<LoginScreen> {
projectsList, projectsList,
'facilityName', 'facilityName',
onSelectProject, onSelectProject,
model); authenticationViewModel);
}, },
validator: ( validator: (value) {
value) {
if (value != if (value !=
null && null &&
value value
@ -480,15 +412,15 @@ class _LoginScreenState extends State<LoginScreen> {
.login, .login,
color: HexColor( color: HexColor(
'#D02127'), '#D02127'),
disabled: model.userInfo disabled: authenticationViewModel.userInfo
.userID == null || .userID == null ||
model.userInfo authenticationViewModel.userInfo
.password == .password ==
null, null,
fontWeight: FontWeight fontWeight: FontWeight
.bold, .bold,
onPressed: () { onPressed: () {
login(context, model); login(context);
}, },
)), )),
], ],
@ -499,10 +431,9 @@ class _LoginScreenState extends State<LoginScreen> {
], ],
) )
])) ]))
]) ]),
: Center(child: AppLoaderWidget()),
), ),
), ); );
} }
SizedBox buildSizedBox() { SizedBox buildSizedBox() {
@ -511,15 +442,14 @@ class _LoginScreenState extends State<LoginScreen> {
); );
} }
login(context, login(context,) async {
AuthenticationViewModel model,) async {
if (loginFormKey.currentState.validate()) { if (loginFormKey.currentState.validate()) {
loginFormKey.currentState.save(); loginFormKey.currentState.save();
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
await model.login(model.userInfo); await authenticationViewModel.login(authenticationViewModel.userInfo);
if (model.state == ViewState.ErrorLocal) { if (authenticationViewModel.state == ViewState.ErrorLocal) {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
Helpers.showErrorToast(model.error); Helpers.showErrorToast(authenticationViewModel.error);
} else { } else {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
@ -527,7 +457,7 @@ class _LoginScreenState extends State<LoginScreen> {
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) => builder: (BuildContext context) =>
VerificationMethodsScreen( VerificationMethodsScreen(
password: model.userInfo.password, password: authenticationViewModel.userInfo.password,
), ),
), ),
); );
@ -535,23 +465,23 @@ class _LoginScreenState extends State<LoginScreen> {
} }
} }
onSelectProject(index, AuthenticationViewModel model) { onSelectProject(index) {
setState(() { setState(() {
model.userInfo.projectID = projectsList[index].facilityId; authenticationViewModel.userInfo.projectID = projectsList[index].facilityId;
projectIdController.text = projectsList[index].facilityName; projectIdController.text = projectsList[index].facilityName;
}); });
primaryFocus.unfocus(); primaryFocus.unfocus();
} }
getProjects(memberID, AuthenticationViewModel model)async { getProjects(memberID)async {
if (memberID != null && memberID != '') { if (memberID != null && memberID != '') {
if (projectsList.length == 0) { if (projectsList.length == 0) {
await model.getHospitalsList(memberID); await authenticationViewModel.getHospitalsList(memberID);
if(model.state == ViewState.Idle) { if(authenticationViewModel.state == ViewState.Idle) {
projectsList = model.hospitals; projectsList = authenticationViewModel.hospitals;
setState(() { setState(() {
model.userInfo.projectID = projectsList[0].facilityId; authenticationViewModel.userInfo.projectID = projectsList[0].facilityId;
projectIdController.text = projectsList[0].facilityName; projectIdController.text = projectsList[0].facilityName;
}); });
} }

@ -4,8 +4,8 @@ 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/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/doctor_profile_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/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/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';
@ -19,7 +19,6 @@ import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../../config/size_config.dart'; import '../../config/size_config.dart';
import '../../core/viewModel/doctor_profile_view_model.dart';
import '../../landing_page.dart'; import '../../landing_page.dart';
import '../../routes.dart'; import '../../routes.dart';
import '../../util/dr_app_shared_pref.dart'; import '../../util/dr_app_shared_pref.dart';
@ -46,20 +45,17 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
DoctorProfileViewModel doctorProfileViewModel; DoctorProfileViewModel doctorProfileViewModel;
AuthMethodTypes fingerPrintBefore; AuthMethodTypes fingerPrintBefore;
AuthMethodTypes selectedOption; AuthMethodTypes selectedOption;
AuthenticationViewModel model; AuthenticationViewModel authenticationViewModel;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
doctorProfileViewModel = Provider.of<DoctorProfileViewModel>(context); doctorProfileViewModel = Provider.of<DoctorProfileViewModel>(context);
projectsProvider = Provider.of<ProjectViewModel>(context); projectsProvider = Provider.of<ProjectViewModel>(context);
return BaseView<AuthenticationViewModel>( authenticationViewModel = Provider.of<AuthenticationViewModel>(context);
onModelReady: (model) async {
this.model = model; return AppScaffold(
await model.getInitUserInfo();
},
builder: (_, model, w) => AppScaffold(
isShowAppBar: false, isShowAppBar: false,
baseViewModel: model, // baseViewModel: model,
body: SingleChildScrollView( body: SingleChildScrollView(
child: Center( child: Center(
child: FractionallySizedBox( child: FractionallySizedBox(
@ -77,7 +73,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
SizedBox( SizedBox(
height: 100, height: 100,
), ),
model.user != null && isMoreOption == false authenticationViewModel.user != null && isMoreOption == false
? Column( ? Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.spaceEvenly, MainAxisAlignment.spaceEvenly,
@ -86,7 +82,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
AppText( AppText(
TranslationBase.of(context).welcomeBack), TranslationBase.of(context).welcomeBack),
AppText( AppText(
Helpers.capitalize(model.user.doctorName), Helpers.capitalize(authenticationViewModel.user.doctorName),
fontSize: SizeConfig.textMultiplier * 3.5, fontSize: SizeConfig.textMultiplier * 3.5,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
@ -121,8 +117,8 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
fontSize: 14), fontSize: 14),
), ),
subtitle: AppText( subtitle: AppText(
model.getType( authenticationViewModel.getType(
model.user authenticationViewModel.user
.logInTypeID, .logInTypeID,
context), context),
fontSize: 14, fontSize: 14,
@ -131,17 +127,16 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
flex: 2, flex: 2,
child: ListTile( child: ListTile(
title: AppText( title: AppText(
model.user.editedOn != authenticationViewModel.user.editedOn !=
null null
? DateUtils.getDayMonthYearDateFormatted( ? DateUtils.getDayMonthYearDateFormatted(
DateUtils.convertStringToDate( DateUtils.convertStringToDate(
model.user authenticationViewModel.user
.editedOn)) .editedOn))
: model.user.createdOn != : authenticationViewModel.user.createdOn !=
null null
? DateUtils.getDayMonthYearDateFormatted( ? DateUtils.getDayMonthYearDateFormatted(
DateUtils.convertStringToDate(model DateUtils.convertStringToDate(authenticationViewModel.user
.user
.createdOn)) .createdOn))
: '--', : '--',
textAlign: textAlign:
@ -151,17 +146,16 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
FontWeight.w800, FontWeight.w800,
), ),
subtitle: AppText( subtitle: AppText(
model.user.editedOn != authenticationViewModel.user.editedOn !=
null null
? DateUtils.getHour( ? DateUtils.getHour(
DateUtils.convertStringToDate( DateUtils.convertStringToDate(
model.user authenticationViewModel.user
.editedOn)) .editedOn))
: model.user.createdOn != : authenticationViewModel.user.createdOn !=
null null
? DateUtils.getHour( ? DateUtils.getHour(
DateUtils.convertStringToDate(model DateUtils.convertStringToDate(authenticationViewModel.user
.user
.createdOn)) .createdOn))
: '--', : '--',
textAlign: textAlign:
@ -194,7 +188,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
textAlign: TextAlign.start, textAlign: TextAlign.start,
), ),
]), ]),
model.user != null && isMoreOption == false authenticationViewModel.user != null && isMoreOption == false
? Column( ? Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -213,10 +207,10 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
.Fingerprint, true) .Fingerprint, true)
}, },
child: VerificationMethodsList( child: VerificationMethodsList(
model: model, authenticationViewModel:authenticationViewModel,
authMethodType: SelectedAuthMethodTypesService authMethodType: SelectedAuthMethodTypesService
.getMethodsTypeService( .getMethodsTypeService(
model.user authenticationViewModel.user
.logInTypeID), .logInTypeID),
authenticateUser: authenticateUser:
(AuthMethodTypes (AuthMethodTypes
@ -229,7 +223,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
), ),
Expanded( Expanded(
child: VerificationMethodsList( child: VerificationMethodsList(
model: model, authenticationViewModel:authenticationViewModel,
authMethodType: authMethodType:
AuthMethodTypes.MoreOptions, AuthMethodTypes.MoreOptions,
onShowMore: () { onShowMore: () {
@ -251,7 +245,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: VerificationMethodsList( child: VerificationMethodsList(
model: model, authenticationViewModel:authenticationViewModel,
authMethodType: authMethodType:
AuthMethodTypes.Fingerprint, AuthMethodTypes.Fingerprint,
authenticateUser: authenticateUser:
@ -264,7 +258,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
)), )),
Expanded( Expanded(
child: VerificationMethodsList( child: VerificationMethodsList(
model: model, authenticationViewModel:authenticationViewModel,
authMethodType: authMethodType:
AuthMethodTypes.FaceID, AuthMethodTypes.FaceID,
authenticateUser: authenticateUser:
@ -284,7 +278,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: VerificationMethodsList( child: VerificationMethodsList(
model: model, authenticationViewModel:authenticationViewModel,
authMethodType: AuthMethodTypes authMethodType: AuthMethodTypes
.SMS, .SMS,
authenticateUser: authenticateUser:
@ -296,7 +290,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
)), )),
Expanded( Expanded(
child: VerificationMethodsList( child: VerificationMethodsList(
model: model, authenticationViewModel:authenticationViewModel,
authMethodType: authMethodType:
AuthMethodTypes.WhatsApp, AuthMethodTypes.WhatsApp,
authenticateUser: authenticateUser:
@ -320,7 +314,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
), ),
), ),
), ),
bottomSheet: model.user == null ? SizedBox(height: 0,) : Container( bottomSheet: authenticationViewModel.user == null ? SizedBox(height: 0,) : Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: BorderRadius.all( borderRadius: BorderRadius.all(
@ -353,8 +347,6 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
), ),
), ),
),), ),),
)
); );
} }
@ -365,12 +357,12 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
await model.sendActivationCodeForDoctorApp(authMethodType:authMethodType, password: widget.password ); await authenticationViewModel.sendActivationCodeForDoctorApp(authMethodType:authMethodType, password: widget.password );
if (model.state == ViewState.ErrorLocal) { if (authenticationViewModel.state == ViewState.ErrorLocal) {
Helpers.showErrorToast(model.error); Helpers.showErrorToast(authenticationViewModel.error);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
} else { } else {
model.setDataAfterSendActivationSuccsess(model.activationCodeForDoctorAppRes); authenticationViewModel.setDataAfterSendActivationSuccsess(authenticationViewModel.activationCodeForDoctorAppRes);
sharedPref.setString(PASSWORD, widget.password); sharedPref.setString(PASSWORD, widget.password);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
this.startSMSService(authMethodType); this.startSMSService(authMethodType);
@ -385,14 +377,14 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async { sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
await model await authenticationViewModel
.sendActivationCodeVerificationScreen(authMethodType); .sendActivationCodeVerificationScreen(authMethodType);
if (model.state == ViewState.ErrorLocal) { if (authenticationViewModel.state == ViewState.ErrorLocal) {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
Helpers.showErrorToast(model.error); Helpers.showErrorToast(authenticationViewModel.error);
} else { } else {
model.setDataAfterSendActivationSuccsess(model.activationCodeVerificationScreenRes); authenticationViewModel.setDataAfterSendActivationSuccsess(authenticationViewModel.activationCodeVerificationScreenRes);
if (authMethodType == AuthMethodTypes.SMS || if (authMethodType == AuthMethodTypes.SMS ||
authMethodType == AuthMethodTypes.WhatsApp) { authMethodType == AuthMethodTypes.WhatsApp) {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
@ -432,7 +424,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
} }
sendActivationCode(AuthMethodTypes authMethodType) async { sendActivationCode(AuthMethodTypes authMethodType) async {
if (model.user != null) { if (authenticationViewModel.user != null) {
sendActivationCodeVerificationScreen(authMethodType); sendActivationCodeVerificationScreen(authMethodType);
} else { } else {
sendActivationCodeByOtpNotificationType(authMethodType); sendActivationCodeByOtpNotificationType(authMethodType);
@ -444,7 +436,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
new SMSOTP( new SMSOTP(
context, context,
type, type,
model.loggedUser != null ? model.loggedUser.mobileNumber : model.user.mobile, authenticationViewModel.loggedUser != null ? authenticationViewModel.loggedUser.mobileNumber : authenticationViewModel.user.mobile,
(value) { (value) {
showDialog( showDialog(
context: context, context: context,
@ -465,14 +457,14 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes,
isActive) async { isActive) async {
if (isActive) { if (isActive) {
await model.showIOSAuthMessages(); await authenticationViewModel.showIOSAuthMessages();
if (!mounted) return; if (!mounted) return;
if (model.user != null && if (authenticationViewModel.user != null &&
(SelectedAuthMethodTypesService.getMethodsTypeService( (SelectedAuthMethodTypesService.getMethodsTypeService(
model.user.logInTypeID) == authenticationViewModel.user.logInTypeID) ==
AuthMethodTypes.Fingerprint || AuthMethodTypes.Fingerprint ||
SelectedAuthMethodTypesService.getMethodsTypeService( SelectedAuthMethodTypesService.getMethodsTypeService(
model.user.logInTypeID) == AuthMethodTypes.FaceID)) { authenticationViewModel.user.logInTypeID) == AuthMethodTypes.FaceID)) {
this.sendActivationCode(authMethodTypes); this.sendActivationCode(authMethodTypes);
} else { } else {
setState(() { setState(() {
@ -483,19 +475,19 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
} }
checkActivationCode({value}) async { checkActivationCode({value}) async {
await model.checkActivationCodeForDoctorApp(activationCode: value); await authenticationViewModel.checkActivationCodeForDoctorApp(activationCode: value);
if (model.state == ViewState.ErrorLocal) { if (authenticationViewModel.state == ViewState.ErrorLocal) {
Navigator.pop(context); Navigator.pop(context);
Helpers.showErrorToast(model.error); Helpers.showErrorToast(authenticationViewModel.error);
} else { } else {
await model.onCheckActivationCodeSuccess(); await authenticationViewModel.onCheckActivationCodeSuccess();
navigateToLandingPage(); navigateToLandingPage();
} }
} }
navigateToLandingPage() { navigateToLandingPage() {
if (model.state == ViewState.ErrorLocal) { if (authenticationViewModel.state == ViewState.ErrorLocal) {
Helpers.showErrorToast(model.error); Helpers.showErrorToast(authenticationViewModel.error);
} else { } else {
projectsProvider.isLogin = true; projectsProvider.isLogin = true;

@ -75,13 +75,14 @@ class _HomeScreenState extends State<HomeScreen> {
var clinicId; var clinicId;
var _patientSearchFormValues; var _patientSearchFormValues;
AuthenticationViewModel _IMEIViewModel = locator<AuthenticationViewModel>(); AuthenticationViewModel authenticationViewModel;
void didChangeDependencies() async { void didChangeDependencies() async {
super.didChangeDependencies(); super.didChangeDependencies();
if (_isInit) { if (_isInit) {
projectsProvider = Provider.of<ProjectViewModel>(context); projectsProvider = Provider.of<ProjectViewModel>(context);
authenticationViewModel = Provider.of<AuthenticationViewModel>(context);
projectsProvider.getDoctorClinicsList(); projectsProvider.getDoctorClinicsList();
// _firebaseMessaging.setAutoInitEnabled(true); // _firebaseMessaging.setAutoInitEnabled(true);
@ -97,7 +98,7 @@ class _HomeScreenState extends State<HomeScreen> {
_firebaseMessaging.getToken().then((String token) async { _firebaseMessaging.getToken().then((String token) async {
if (token != '') { if (token != '') {
DEVICE_TOKEN = token; DEVICE_TOKEN = token;
await _IMEIViewModel.insertDeviceImei(); await authenticationViewModel.insertDeviceImei();
changeIsLoading(false); changeIsLoading(false);
} }

@ -11,14 +11,14 @@ class VerificationMethodsList extends StatefulWidget {
final AuthMethodTypes authMethodType; final AuthMethodTypes authMethodType;
final Function(AuthMethodTypes type, bool isActive) authenticateUser; final Function(AuthMethodTypes type, bool isActive) authenticateUser;
final Function onShowMore; final Function onShowMore;
final AuthenticationViewModel model; final AuthenticationViewModel authenticationViewModel;
const VerificationMethodsList( const VerificationMethodsList(
{Key key, {Key key,
this.authMethodType, this.authMethodType,
this.authenticateUser, this.authenticateUser,
this.onShowMore, this.onShowMore,
this.model}) this.authenticationViewModel})
: super(key: key); : super(key: key);
@override @override
@ -54,7 +54,7 @@ class _VerificationMethodsListState extends State<VerificationMethodsList> {
return MethodTypeCard( return MethodTypeCard(
assetPath: 'assets/images/verification_fingerprint_icon.png', assetPath: 'assets/images/verification_fingerprint_icon.png',
onTap: () async { onTap: () async {
if (await widget.model if (await widget.authenticationViewModel
.checkIfBiometricAvailable(BiometricType.fingerprint)) { .checkIfBiometricAvailable(BiometricType.fingerprint)) {
widget.authenticateUser(AuthMethodTypes.Fingerprint, true); widget.authenticateUser(AuthMethodTypes.Fingerprint, true);
@ -67,7 +67,7 @@ class _VerificationMethodsListState extends State<VerificationMethodsList> {
return MethodTypeCard( return MethodTypeCard(
assetPath: 'assets/images/verification_faceid_icon.png', assetPath: 'assets/images/verification_faceid_icon.png',
onTap: () async { onTap: () async {
if (await widget.model if (await widget.authenticationViewModel
.checkIfBiometricAvailable(BiometricType.face)) { .checkIfBiometricAvailable(BiometricType.face)) {
widget.authenticateUser(AuthMethodTypes.FaceID, true); widget.authenticateUser(AuthMethodTypes.FaceID, true);
} }

Loading…
Cancel
Save