From c5bbb0495a834b74f1a55a6e5b76fe3ceefb92de Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Thu, 28 May 2020 13:52:59 +0300 Subject: [PATCH] add login logic with silent options --- .../vital_sign/vital_sign_details_screen.dart | 152 ++++++++++++------ lib/widgets/auth/verification_methods.dart | 146 +++++++++++++---- .../profile/profile_medical_info_widget.dart | 2 +- pubspec.lock | 7 + pubspec.yaml | 27 +--- 5 files changed, 223 insertions(+), 111 deletions(-) diff --git a/lib/screens/patients/profile/vital_sign/vital_sign_details_screen.dart b/lib/screens/patients/profile/vital_sign/vital_sign_details_screen.dart index a7155e01..d2cb5380 100644 --- a/lib/screens/patients/profile/vital_sign/vital_sign_details_screen.dart +++ b/lib/screens/patients/profile/vital_sign/vital_sign_details_screen.dart @@ -1,16 +1,70 @@ +import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; +import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; +import 'package:doctor_app_flutter/models/patient/vital_sign_req_model.dart'; +import 'package:doctor_app_flutter/providers/patients_provider.dart'; import 'package:doctor_app_flutter/routes.dart'; +import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import '../../../../config/size_config.dart'; import '../../../../models/patient/vital_sign_res_model.dart'; import '../../../../widgets/patients/profile/profile_medical_info_widget.dart'; import '../../../../widgets/shared/app_scaffold_widget.dart'; -import '../../../../widgets/shared/rounded_container_widget.dart'; +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); -class VitalSignDetailsScreen extends StatelessWidget { +class VitalSignDetailsScreen extends StatefulWidget { // VitalSignDetailsScreen({Key key, this.vitalSing}) : super(key: key); + @override + _VitalSignDetailsScreenState createState() => _VitalSignDetailsScreenState(); +} + +class _VitalSignDetailsScreenState extends State { VitalSignResModel vitalSing; String url = "assets/images/"; + + PatientsProvider patientsProv; + var _isInit = true; + + /* + *@author: Elham Rababah + *@Date:28/4/2020 + *@param: context + *@return: + *@desc: getVitalSignList Function + */ + getVitalSignList(context) async { + final routeArgs = ModalRoute.of(context).settings.arguments as Map; + PatiantInformtion patient = routeArgs['patient']; + String token = await sharedPref.getString(TOKEN); + String type = await sharedPref.getString(SLECTED_PATIENT_TYPE); + int inOutpatientType = 1; + if (type == '0') { + inOutpatientType = 2; + } + print(type); + VitalSignReqModel vitalSignReqModel = VitalSignReqModel( + patientID: patient.patientId, + projectID: patient.projectId, + tokenID: token, + patientTypeID: patient.patientType, + inOutpatientType: inOutpatientType, + languageID: 2, + transNo: + patient.admissionNo != null ? int.parse(patient.admissionNo) : 0); + patientsProv.getPatientVitalSign(vitalSignReqModel.toJson()); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (_isInit) { + patientsProv = Provider.of(context); + getVitalSignList(context); + } + _isInit = false; + } + final double contWidth = SizeConfig.realScreenWidth * 0.70; @override @@ -19,58 +73,54 @@ class VitalSignDetailsScreen extends StatelessWidget { vitalSing = routeArgs['vitalSing']; return AppScaffold( appBarTitle: "vital Sing ", - body: RoundedContainer( - height: SizeConfig.realScreenHeight * 0.7, - child: CustomScrollView( - primary: false, - slivers: [ - SliverPadding( - padding: const EdgeInsets.all(10), - sliver: SliverGrid.count( - childAspectRatio: 0.7, - crossAxisSpacing: 10, - mainAxisSpacing: 0, - crossAxisCount: 3, - children: [ - InkWell( - onTap: (){ - Navigator.of(context).pushNamed(BODY_MEASUREMENTS); - }, - child: CircleAvatarWidget( - des: 'Body Measurements', - url: url + 'heartbeat.png', - ), - ), - CircleAvatarWidget( - des: 'Temperature', - url: url + 'heartbeat.png', - ), - CircleAvatarWidget( - des: 'Pulse', - url: url + 'heartbeat.png', - ), - CircleAvatarWidget( - des: 'Respiration', - url: url + 'heartbeat.png', - ), - CircleAvatarWidget( - des: 'Blood Pressure', - url: url + 'heartbeat.png', - ), - CircleAvatarWidget( - des: 'Oxygenation', - url: url + 'heartbeat.png', - ), - CircleAvatarWidget( - des: 'Pain Scale', + body: CustomScrollView( + primary: false, + slivers: [ + SliverPadding( + padding: const EdgeInsets.all(10), + sliver: SliverGrid.count( + childAspectRatio: 0.7, + crossAxisSpacing: 10, + mainAxisSpacing: 0, + crossAxisCount: 3, + children: [ + InkWell( + onTap: (){ + Navigator.of(context).pushNamed(BODY_MEASUREMENTS); + }, + child: CircleAvatarWidget( + des: 'Body Measurements', url: url + 'heartbeat.png', ), - ], - ), + ), + CircleAvatarWidget( + des: 'Temperature', + url: url + 'heartbeat.png', + ), + CircleAvatarWidget( + des: 'Pulse', + url: url + 'heartbeat.png', + ), + CircleAvatarWidget( + des: 'Respiration', + url: url + 'heartbeat.png', + ), + CircleAvatarWidget( + des: 'Blood Pressure', + url: url + 'heartbeat.png', + ), + CircleAvatarWidget( + des: 'Oxygenation', + url: url + 'heartbeat.png', + ), + CircleAvatarWidget( + des: 'Pain Scale', + url: url + 'heartbeat.png', + ), + ], ), - ], - ), - // height: 500, + ), + ], )); } } diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 0eb11866..061d85c6 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -1,4 +1,5 @@ -import 'package:doctor_app_flutter/widgets/shared/rounded_container_widget.dart'; +import 'dart:io' show Platform; + import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; @@ -31,6 +32,7 @@ class _VerificationMethodsState extends State { MainAxisAlignment spaceBetweenMethods = MainAxisAlignment.spaceBetween; Future _loggedUserFuture; var _loggedUser; + var verificationMethod; @override void initState() { super.initState(); @@ -43,6 +45,14 @@ class _VerificationMethodsState extends State { }); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final routeArgs = ModalRoute.of(context).settings.arguments as Map; + verificationMethod = + routeArgs != null ? routeArgs['verificationMethod'] : null; + } + @override Widget build(BuildContext context) { AuthProvider authProv = Provider.of(context); @@ -63,7 +73,9 @@ class _VerificationMethodsState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - "Please choose one of the Following option to verify", + hideSilentMethods() + ? 'As a first step, you need to verify by one of those methods' + : 'Please choose one of the Following option to verify', style: TextStyle( fontSize: 3.5 * SizeConfig.textMultiplier, ), @@ -84,30 +96,28 @@ class _VerificationMethodsState extends State { mainAxisSpacing: 5, crossAxisCount: 2, children: [ - buildVerificationMethod( - context, - 'assets/images/verification_fingerprint_icon.png', - 'Fingerprint', - () {}), - buildVerificationMethod( - context, - 'assets/images/verification_faceid_icon.png', - 'Face ID', - () {}), - buildVerificationMethod( - context, - 'assets/images/verification_whatsapp_icon.png', - 'WhatsApp', () { - sendActivationCodeByOtpNotificationType( - 2, authProv); - }), - buildVerificationMethod( - context, - 'assets/images/verification_sms_icon.png', - 'SMS', () { - sendActivationCodeByOtpNotificationType( - 1, authProv); - }), + Visibility( + visible: hideSilentMethods() ? false : true, + child: buildFingerprintMethod( + context, authProv), + replacement: + buildWhatsAppMethod(context, authProv), + ), + Visibility( + visible: hideSilentMethods() ? false : true, + child: buildFaceIDMethod(context, authProv), + replacement: + buildSMSMethod(context, authProv), + ), + Visibility( + visible: + hideSilentMethods() ? false : true, + child: buildWhatsAppMethod( + context, authProv)), + Visibility( + visible: hideSilentMethods() ? false : true, + child: buildSMSMethod(context, authProv), + ), ], ), ), @@ -115,9 +125,9 @@ class _VerificationMethodsState extends State { ), // height: 500, ), - SizedBox( - // height: 20, - ) + SizedBox( + // height: 20, + ) ], ), ); @@ -126,6 +136,67 @@ class _VerificationMethodsState extends State { }); } + /* + *@author: Elham Rababah + *@Date:28/5/2020 + *@param: BuildContext context, AuthProvider authProv + *@return: Center widget + *@desc: buildSMSMethod Methods widget + */ + Center buildSMSMethod(BuildContext context, AuthProvider authProv) { + return buildVerificationMethod( + context, 'assets/images/verification_sms_icon.png', 'SMS', () { + sendActivationCodeByOtpNotificationType(1, authProv); + }); + } + /* + *@author: Elham Rababah + *@Date:28/5/2020 + *@param: BuildContext context, AuthProvider authProv + *@return: Center widget + *@desc: build WhatsApp Methods widget + */ + Center buildWhatsAppMethod(BuildContext context, AuthProvider authProv) { + return buildVerificationMethod( + context, 'assets/images/verification_whatsapp_icon.png', 'WhatsApp', + () { + sendActivationCodeByOtpNotificationType(2, authProv); + }); + } +/* + *@author: Elham Rababah + *@Date:28/5/2020 + *@param: BuildContext context, AuthProvider authProv + *@return: Center widget + *@desc: build FaceID Methods widget + */ + Center buildFaceIDMethod(BuildContext context, AuthProvider authProv) { + return buildVerificationMethod( + context, 'assets/images/verification_faceid_icon.png', 'Face ID', () { + sendActivationCodeByOtpNotificationType(3, authProv); + }); + } +/* + *@author: Elham Rababah + *@Date:28/5/2020 + *@param: BuildContext context, AuthProvider authProv + *@return: Center widget + *@desc: build Fingerprint Methods widget + */ + Center buildFingerprintMethod(BuildContext context, AuthProvider authProv) { + return buildVerificationMethod(context, + 'assets/images/verification_fingerprint_icon.png', 'Fingerprint', () { + sendActivationCodeByOtpNotificationType(4, authProv); + }); + } + + /* + *@author: Elham Rababah + *@Date:28/5/2020 + *@param: BuildContext context, AuthProvider authProv + *@return: Center widget + *@desc: build Verification Methods widget + */ Center buildVerificationMethod(context, url, dec, Function fun) { return Center( child: InkWell( @@ -168,6 +239,10 @@ class _VerificationMethodsState extends State { ); } + bool hideSilentMethods() { + return verificationMethod == 4 || verificationMethod == 3 ? true : false; + } + /* *@author: Elham Rababah *@Date:15/4/2020 @@ -176,9 +251,10 @@ class _VerificationMethodsState extends State { *@desc: send Activation Code By Otp Notification Type */ sendActivationCodeByOtpNotificationType(oTPSendType, AuthProvider authProv) { - widget.changeLoadingStata(true); // TODO : build enum for verfication method if (oTPSendType == 1 || oTPSendType == 2) { + widget.changeLoadingStata(true); + Map model = { "LogInTokenID": _loggedUser['LogInTokenID'], "Channel": 9, @@ -190,10 +266,7 @@ class _VerificationMethodsState extends State { "UserName": _loggedUser['List_MemberInformation'][0]['MemberID'], "OTP_SendType": oTPSendType }; - // print('$_loggedUser'); - // print(oTPSendType); authProv.sendActivationCodeByOtpNotificationType(model).then((res) { - // Navigator.of(context).pushNamed(VERIFY_ACCOUNT); widget.changeLoadingStata(false); if (res['MessageStatus'] == 1) { @@ -202,7 +275,6 @@ class _VerificationMethodsState extends State { print(res['ErrorEndUserMessage']); helpers.showErrorToast(res['ErrorEndUserMessage']); } - // Navigator.of(context).pushNamed(HOME); }).catchError((err) { print('$err'); widget.changeLoadingStata(false); @@ -211,6 +283,12 @@ class _VerificationMethodsState extends State { }); } else { // TODO route to this page with parameters to inicate we should present 2 option + if (Platform.isAndroid && oTPSendType == 3) { + helpers.showErrorToast('Your device not support this feature'); + } else { + Navigator.of(context).pushNamed(VERIFICATION_METHODS, + arguments: {'verificationMethod': oTPSendType}); + } } } } diff --git a/lib/widgets/patients/profile/profile_medical_info_widget.dart b/lib/widgets/patients/profile/profile_medical_info_widget.dart index 3f40204b..657690be 100644 --- a/lib/widgets/patients/profile/profile_medical_info_widget.dart +++ b/lib/widgets/patients/profile/profile_medical_info_widget.dart @@ -47,7 +47,7 @@ class ProfileMedicalInfoWidget extends StatelessWidget { children: [ InkWell( onTap: () { - navigator(context, VITAL_SIGN); + navigator(context, VITAL_SIGN_DETAILS); }, child: CircleAvatarWidget( des: 'Vital Sign', diff --git a/pubspec.lock b/pubspec.lock index 9b4511ab..26be4b14 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -225,6 +225,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.4" + device_info: + dependency: "direct main" + description: + name: device_info + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.2+4" fixnum: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f87e1480..c784e678 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,12 +36,11 @@ dependencies: maps_launcher: ^1.2.0 url_launcher: ^5.4.5 charts_flutter: ^0.9.0 - # Qr code Scanner barcode_scan: ^3.0.1 - # permissions permission_handler: ^5.0.0+hotfix.3 + device_info: ^0.4.2+4 @@ -71,29 +70,7 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - - assets/images/login_icon.png - - assets/images/hospital_icon.png - - assets/images/password_icon.png - - assets/images/user_id_icon.png - - assets/images/login_btn_arrow_icon.png - - assets/images/dr_avatar.png - - assets/images/verification_fingerprint_lg_icon.png - - assets/images/verification_faceid_lg_icon.png - - assets/images/verification_sms_lg_icon.png - - assets/images/verification_whatsapp_lg_icon.png - - assets/images/verification_fingerprint_icon.png - - assets/images/verification_faceid_icon.png - - assets/images/verification_sms_icon.png - - assets/images/verification_whatsapp_icon.png - - assets/images/close_icon.png - - assets/images/welcome_login_icon.png - - assets/images/verified_icon.png - - assets/images/heartbeat.png - - assets/images/lab.png - - assets/images/note.png - - assets/images/radiology-1.png - - assets/images/qr_code.png - - assets/images/qr_code_white.png + - assets/images/ # - images/a_dot_ham.jpeg