From 38f134b6ffe8f66e84d1ab11dc75d9c8964945a8 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Sun, 11 Jul 2021 15:25:15 +0300 Subject: [PATCH] Bug PAP-884 fixed, email was not updating. --- .../medical/reports_monthly_view_model.dart | 13 ++-- .../medical/reports/monthly_reports.dart | 62 +++++++++---------- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/lib/core/viewModels/medical/reports_monthly_view_model.dart b/lib/core/viewModels/medical/reports_monthly_view_model.dart index adb7223e..15ac9219 100644 --- a/lib/core/viewModels/medical/reports_monthly_view_model.dart +++ b/lib/core/viewModels/medical/reports_monthly_view_model.dart @@ -14,6 +14,10 @@ class ReportsMonthlyViewModel extends BaseViewModel { ReportsService _reportsService = locator(); String get userAgreementContent => _reportsService.userAgreementContent; + bool get receiveHealthSummaryReport => _reportsService?.user?.receiveHealthSummaryReport ?? false; + set receiveHealthSummaryReport(bool val) { + _reportsService?.user?.receiveHealthSummaryReport = val; + } getUserTermsAndConditions() async { setState(ViewState.Busy); @@ -26,14 +30,9 @@ class ReportsMonthlyViewModel extends BaseViewModel { } } - updatePatientHealthSummaryReport( - {String message, - bool isSummary, - bool isUpdateEmail = false, - String email}) async { + updatePatientHealthSummaryReport({String message, bool isSummary, bool isUpdateEmail = false, String email}) async { setState(ViewState.BusyLocal); - await _reportsService.updatePatientHealthSummaryReport( - isSummary: isSummary); + await _reportsService.updatePatientHealthSummaryReport(isSummary: isSummary); if (_reportsService.hasError) { error = _reportsService.error; AppToast.showErrorToast(message: error); diff --git a/lib/pages/medical/reports/monthly_reports.dart b/lib/pages/medical/reports/monthly_reports.dart index 4484bd5f..80f6ac76 100644 --- a/lib/pages/medical/reports/monthly_reports.dart +++ b/lib/pages/medical/reports/monthly_reports.dart @@ -19,15 +19,24 @@ class MonthlyReportsPage extends StatefulWidget { } class _MonthlyReportsPageState extends State { - bool isAgree = false; - bool isSummary = false; - String email = ""; + bool isAgree; + bool isSummary; + String email; final formKey = GlobalKey(); @override Widget build(BuildContext context) { - return BaseView( - builder: (_, model, w) => AppScaffold( + return BaseView(builder: (_, model, w) { + if (isSummary == null) { + isSummary = model.receiveHealthSummaryReport; + } + if (isAgree == null) { + isAgree = model.receiveHealthSummaryReport; + } + if (email == null) { + email = model?.user?.emailAddress ?? ""; + } + return AppScaffold( isShowAppBar: true, appBarTitle: TranslationBase.of(context).monthlyReports, body: SingleChildScrollView( @@ -41,15 +50,10 @@ class _MonthlyReportsPageState extends State { Container( padding: EdgeInsets.all(9), height: 55, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(8)), - shape: BoxShape.rectangle, - border: Border.all(color: Colors.grey)), + decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(8)), shape: BoxShape.rectangle, border: Border.all(color: Colors.grey)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Texts( TranslationBase.of(context).patientHealthSummaryReport, bold: true, @@ -62,12 +66,12 @@ class _MonthlyReportsPageState extends State { setState(() { isSummary = !isSummary; }); - if(!isSummary) { + if (!isSummary) { GifLoaderDialogUtils.showMyDialog(context); - await model.updatePatientHealthSummaryReport( - message: TranslationBase - .of(context) - .updateSuccessfully, isSummary: isSummary); + await model.updatePatientHealthSummaryReport(message: TranslationBase.of(context).updateSuccessfully, isSummary: isSummary); + model.receiveHealthSummaryReport = isSummary; + isAgree = isSummary; + model.user.emailAddress = ""; GifLoaderDialogUtils.hideDialog(context); } }, @@ -80,11 +84,11 @@ class _MonthlyReportsPageState extends State { ), Container( margin: EdgeInsets.all(8), - child: TextFields( + child: TextFields( fillColor: Colors.red, hintText: 'email@email.com', fontSize: 20, - initialValue: model.user.emailAddress, + initialValue: email, fontWeight: FontWeight.w600, onChanged: (text) { email = text; @@ -111,8 +115,7 @@ class _MonthlyReportsPageState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( - child: Texts(TranslationBase.of(context) - .toViewTheTermsAndConditions), + child: Texts(TranslationBase.of(context).toViewTheTermsAndConditions), ), InkWell( onTap: () { @@ -156,19 +159,15 @@ class _MonthlyReportsPageState extends State { child: SecondaryButton( textColor: Colors.white, label: TranslationBase.of(context).save, - disabled: (!isAgree || !isSummary ), + disabled: (!isAgree || !isSummary), onTap: () async { final form = formKey.currentState; if (form.validate()) { GifLoaderDialogUtils.showMyDialog(context); await model.updatePatientHealthSummaryReport( - message: TranslationBase - .of(context) - .updateSuccessfully, - isSummary: isSummary, - isUpdateEmail: true, - email: email.isNotEmpty ? email : model.user - .emailAddress); + message: TranslationBase.of(context).updateSuccessfully, isSummary: isSummary, isUpdateEmail: true, email: email.isNotEmpty ? email : model.user.emailAddress); + model.receiveHealthSummaryReport = isSummary; + model.user.emailAddress = email.isNotEmpty ? email : model.user.emailAddress; GifLoaderDialogUtils.hideDialog(context); } }, @@ -177,8 +176,7 @@ class _MonthlyReportsPageState extends State { Padding( padding: const EdgeInsets.all(5.0), child: Texts( - TranslationBase.of(context) - .instructionAgree, + TranslationBase.of(context).instructionAgree, fontWeight: FontWeight.normal, ), ), @@ -191,7 +189,7 @@ class _MonthlyReportsPageState extends State { ), ), ), - ), - ); + ); + }); } }