import 'dart:io' show Platform; import 'package:doctor_app_flutter/config/config.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/viewstate.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/date-utils.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/shared/app_loader_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_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/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; import '../../config/size_config.dart'; import '../../landing_page.dart'; import '../../root_page.dart'; import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; import '../../util/helpers.dart'; import '../../widgets/auth/verification_methods_list.dart'; import 'login_screen.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = Helpers(); class VerificationMethodsScreen extends StatefulWidget { VerificationMethodsScreen({this.password}); final password; @override _VerificationMethodsScreenState createState() => _VerificationMethodsScreenState(); } class _VerificationMethodsScreenState extends State { ProjectViewModel projectsProvider; bool isMoreOption = false; bool onlySMSBox = false; AuthMethodTypes fingerPrintBefore; AuthMethodTypes selectedOption; AuthenticationViewModel authenticationViewModel; @override Widget build(BuildContext context) { projectsProvider = Provider.of(context); authenticationViewModel = Provider.of(context); return AppScaffold( isShowAppBar: false, backgroundColor: Theme.of(context).scaffoldBackgroundColor, // baseViewModel: model, body: SingleChildScrollView( child: Center( child: FractionallySizedBox( child: Container( margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), height: SizeConfig.realScreenHeight * .95, width: SizeConfig.realScreenWidth, child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( child: Column( children: [ SizedBox( height: 100, ), authenticationViewModel.user != null && isMoreOption == false ? Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, children: [ AppText( TranslationBase.of(context).welcomeBack), AppText( Helpers.capitalize(authenticationViewModel.user.doctorName), fontSize: SizeConfig.textMultiplier * 3.5, fontWeight: FontWeight.bold, ), SizedBox( height: 20, ), AppText( TranslationBase.of(context).accountInfo, fontSize: SizeConfig.textMultiplier * 2.5, fontWeight: FontWeight.w600, ), SizedBox( height: 20, ), Card( color: Colors.white, child: Row( children: [ Flexible( flex: 3, child: ListTile( title: Text( TranslationBase.of(context) .lastLoginAt, overflow: TextOverflow.ellipsis, style: TextStyle( fontFamily: 'Poppins', fontWeight: FontWeight .w800, fontSize: 14), ), subtitle: AppText( authenticationViewModel.getType( authenticationViewModel.user .logInTypeID, context), fontSize: 14, ))), Flexible( flex: 2, child: ListTile( title: AppText( authenticationViewModel.user.editedOn != null ? DateUtils.getDayMonthYearDateFormatted( DateUtils.convertStringToDate( authenticationViewModel.user .editedOn)) : authenticationViewModel.user.createdOn != null ? DateUtils.getDayMonthYearDateFormatted( DateUtils.convertStringToDate(authenticationViewModel.user .createdOn)) : '--', textAlign: TextAlign.right, fontSize: 14, fontWeight: FontWeight.w800, ), subtitle: AppText( authenticationViewModel.user.editedOn != null ? DateUtils.getHour( DateUtils.convertStringToDate( authenticationViewModel.user .editedOn)) : authenticationViewModel.user.createdOn != null ? DateUtils.getHour( DateUtils.convertStringToDate(authenticationViewModel.user .createdOn)) : '--', textAlign: TextAlign.right, fontSize: 14, ), )) ], )), ], ) : Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, children: [ this.onlySMSBox == false ? AppText( TranslationBase.of(context) .verifyLoginWith, fontSize: SizeConfig.textMultiplier * 3.5, textAlign: TextAlign.left, ) : AppText( TranslationBase.of(context) .verifyFingerprint2, fontSize: SizeConfig.textMultiplier * 2.5, textAlign: TextAlign.start, ), ]), authenticationViewModel.user != null && isMoreOption == false ? Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( child: InkWell( onTap: () => { // TODO check this logic it seem it will create bug to us authenticateUser( AuthMethodTypes .Fingerprint, true) }, child: VerificationMethodsList( authenticationViewModel:authenticationViewModel, authMethodType: SelectedAuthMethodTypesService .getMethodsTypeService( authenticationViewModel.user .logInTypeID), authenticateUser: (AuthMethodTypes authMethodType, isActive) => authenticateUser( authMethodType, isActive), )), ), Expanded( child: VerificationMethodsList( authenticationViewModel:authenticationViewModel, authMethodType: AuthMethodTypes.MoreOptions, onShowMore: () { setState(() { isMoreOption = true; }); }, )) ]), ]) : Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ onlySMSBox == false ? Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( child: VerificationMethodsList( authenticationViewModel:authenticationViewModel, authMethodType: AuthMethodTypes.Fingerprint, authenticateUser: (AuthMethodTypes authMethodType, isActive) => authenticateUser( authMethodType, isActive), )), Expanded( child: VerificationMethodsList( authenticationViewModel:authenticationViewModel, authMethodType: AuthMethodTypes.FaceID, authenticateUser: (AuthMethodTypes authMethodType, isActive) => authenticateUser( authMethodType, isActive), )) ], ) : SizedBox(), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( child: VerificationMethodsList( authenticationViewModel:authenticationViewModel, authMethodType: AuthMethodTypes .SMS, authenticateUser: ( AuthMethodTypes authMethodType, isActive) => authenticateUser( authMethodType, isActive), )), Expanded( child: VerificationMethodsList( authenticationViewModel:authenticationViewModel, authMethodType: AuthMethodTypes.WhatsApp, authenticateUser: ( AuthMethodTypes authMethodType, isActive) => authenticateUser( authMethodType, isActive), )) ], ), ]), // ) ], ), ), ], ), ), ), ), ), bottomSheet: authenticationViewModel.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: [ AppButton( title: TranslationBase .of(context) .useAnotherAccount, color: Colors.red[700], onPressed: () { projectsProvider.isLogin = true; authenticationViewModel.unverified = false; authenticationViewModel.isLogin = false; Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage( page: RootPage(), ), (r) => false); // Navigator.of(context).pushNamed(LOGIN); }, ), SizedBox(height: 25,) ], ), ), ),), ); } sendActivationCodeByOtpNotificationType( AuthMethodTypes authMethodType) async { if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.showMyDialog(context); await authenticationViewModel.sendActivationCodeForDoctorApp(authMethodType:authMethodType, password: widget.password ); if (authenticationViewModel.state == ViewState.ErrorLocal) { Helpers.showErrorToast(authenticationViewModel.error); GifLoaderDialogUtils.hideDialog(context); } else { authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeForDoctorAppRes); sharedPref.setString(PASSWORD, widget.password); GifLoaderDialogUtils.hideDialog(context); this.startSMSService(authMethodType); } } else { // TODO route to this page with parameters to inicate we should present 2 option if (Platform.isAndroid && authMethodType == AuthMethodTypes.Fingerprint) { Helpers.showErrorToast('Your device not support this feature'); } else {} } } sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async { GifLoaderDialogUtils.showMyDialog(context); await authenticationViewModel .sendActivationCodeVerificationScreen(authMethodType); if (authenticationViewModel.state == ViewState.ErrorLocal) { GifLoaderDialogUtils.hideDialog(context); Helpers.showErrorToast(authenticationViewModel.error); } else { authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeVerificationScreenRes); if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.hideDialog(context); this.startSMSService(authMethodType); } else { checkActivationCode(); } } } authenticateUser(AuthMethodTypes authMethodType, isActive) { if (authMethodType == AuthMethodTypes.Fingerprint || authMethodType == AuthMethodTypes.FaceID) { fingerPrintBefore = authMethodType; } this.selectedOption = fingerPrintBefore != null ? fingerPrintBefore : authMethodType; switch (authMethodType) { case AuthMethodTypes.SMS: sendActivationCode(authMethodType); break; case AuthMethodTypes.WhatsApp: sendActivationCode(authMethodType); break; case AuthMethodTypes.Fingerprint: this.loginWithFingerPrintOrFaceID( AuthMethodTypes.Fingerprint, isActive); break; case AuthMethodTypes.FaceID: this.loginWithFingerPrintOrFaceID(AuthMethodTypes.FaceID, isActive); break; default: break; } sharedPref.setInt(OTP_TYPE, selectedOption.getTypeIdService()); } sendActivationCode(AuthMethodTypes authMethodType) async { if (authenticationViewModel.user != null) { sendActivationCodeVerificationScreen(authMethodType); } else { sendActivationCodeByOtpNotificationType(authMethodType); } } startSMSService(AuthMethodTypes type) { new SMSOTP( context, type, authenticationViewModel.loggedUser != null ? authenticationViewModel.loggedUser.mobileNumber : authenticationViewModel.user.mobile, (value) { showDialog( context: context, builder: (BuildContext context) { return AppLoaderWidget(); }); this.checkActivationCode(value: value); }, () => { print('Faild..'), }, ).displayDialog(context); } loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, isActive) async { if (isActive) { await authenticationViewModel.showIOSAuthMessages(); if (!mounted) return; if (authenticationViewModel.user != null && (SelectedAuthMethodTypesService.getMethodsTypeService( authenticationViewModel.user.logInTypeID) == AuthMethodTypes.Fingerprint || SelectedAuthMethodTypesService.getMethodsTypeService( authenticationViewModel.user.logInTypeID) == AuthMethodTypes.FaceID)) { this.sendActivationCode(authMethodTypes); } else { setState(() { this.onlySMSBox = true; }); } } } checkActivationCode({value}) async { await authenticationViewModel.checkActivationCodeForDoctorApp(activationCode: value); if (authenticationViewModel.state == ViewState.ErrorLocal) { Navigator.pop(context); Helpers.showErrorToast(authenticationViewModel.error); } else { await authenticationViewModel.onCheckActivationCodeSuccess(); navigateToLandingPage(); } } navigateToLandingPage() { if (authenticationViewModel.state == ViewState.ErrorLocal) { Helpers.showErrorToast(authenticationViewModel.error); } else { projectsProvider.isLogin = true; Navigator.pushAndRemoveUntil( context, FadePage( page: LandingPage(), ), (r) => false); } } }