From 2e1c9780d73dd31cf1c97f7720b4234be4d4f8a9 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Mon, 5 Jul 2021 12:14:28 +0300 Subject: [PATCH] PAP-610: prevent show send email button if user have no vaccine --- lib/core/viewModels/vaccine_view_model.dart | 2 +- lib/pages/vaccine/my_vaccines_screen.dart | 323 ++++++++++---------- 2 files changed, 171 insertions(+), 154 deletions(-) diff --git a/lib/core/viewModels/vaccine_view_model.dart b/lib/core/viewModels/vaccine_view_model.dart index 9f8dfecf..37b57da4 100644 --- a/lib/core/viewModels/vaccine_view_model.dart +++ b/lib/core/viewModels/vaccine_view_model.dart @@ -22,7 +22,7 @@ class VaccineViewModel extends BaseViewModel { await _vaccineService.getMyVaccine(); if (_vaccineService.hasError) { error = _vaccineService.error; - setState(ViewState.ErrorLocal); + setState(ViewState.Error); } else setState(ViewState.Idle); } diff --git a/lib/pages/vaccine/my_vaccines_screen.dart b/lib/pages/vaccine/my_vaccines_screen.dart index fb723a1f..27ce8399 100644 --- a/lib/pages/vaccine/my_vaccines_screen.dart +++ b/lib/pages/vaccine/my_vaccines_screen.dart @@ -30,173 +30,190 @@ class _MyVaccinesState extends State { onModelReady: (model) => model.getVaccine(), builder: (BuildContext context, VaccineViewModel model, Widget child) => AppScaffold( - isShowAppBar: true, - appBarTitle: TranslationBase.of(context).myVaccines, - baseViewModel: model, - body: Container( - margin: EdgeInsets.only( - left: SizeConfig.screenWidth * 0.004, - right: SizeConfig.screenWidth * 0.004, - top: SizeConfig.screenWidth * 0.04, - ), - child: Column( - children: [ - RoundedContainer( - backgroundColor: Colors.white, - child: ExpansionTile( - title: Container( - height: 65.0, - child: Text('2018'), - ), - children: [ - Container( - child: ListView.builder( - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: model.vaccineList == null - ? 0 - : model.vaccineList.length, - itemBuilder: (BuildContext context, int index) { - return Column( - children: [ - RoundedContainer( - child: Column( - children: [ - Row( + isShowAppBar: true, + baseViewModel: model, + appBarTitle: TranslationBase.of(context).myVaccines, + body: Container( + margin: EdgeInsets.only( + left: SizeConfig.screenWidth * 0.004, + right: SizeConfig.screenWidth * 0.004, + top: SizeConfig.screenWidth * 0.04, + ), + child: Column( + children: [ + RoundedContainer( + backgroundColor: Colors.white, + child: ExpansionTile( + title: Container( + height: 65.0, + child: Text('2018'), + ), + children: [ + Container( + child: ListView.builder( + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: model.vaccineList == null + ? 0 + : model.vaccineList.length, + itemBuilder: (BuildContext context, int index) { + return Column( + children: [ + RoundedContainer( + child: Column( children: [ - Expanded( - child: Column( - children: [ - Padding( - padding: EdgeInsets.symmetric( - horizontal: 20.0, - vertical: 20.0), - child: Image.network( - model.vaccineList[index] - .doctorImageURL, - height: SizeConfig + Row( + children: [ + Expanded( + child: Column( + children: [ + Padding( + padding: EdgeInsets + .symmetric( + horizontal: + 20.0, + vertical: 20.0), + child: Image.network( + model + .vaccineList[ + index] + .doctorImageURL, + height: SizeConfig .imageSizeMultiplier * - 23, - width: SizeConfig + 23, + width: SizeConfig .imageSizeMultiplier * - 20, - fit: BoxFit.fill, - ), + 20, + fit: BoxFit.fill, + ), + ), + ], ), - ], - ), - flex: 2, - ), - Expanded( - child: Container( - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - model.vaccineList[index] + flex: 2, + ), + Expanded( + child: Container( + child: Column( + crossAxisAlignment: + CrossAxisAlignment + .start, + children: [ + Text( + model + .vaccineList[ + index] .doctorTitle + - model.vaccineList[index] - .doctorName, - style: TextStyle( - fontWeight: + model + .vaccineList[ + index] + .doctorName, + style: TextStyle( + fontWeight: FontWeight.w900, - fontSize: 16.6, - ), - ), - SizedBox(height: 7.0), - Text( - model.vaccineList[index] - .projectName, - style: TextStyle( - fontSize: 17.0, - letterSpacing: 0.5, - ), - ), - SizedBox(height: 7.0), - Text( - model.vaccineList[index] - .vaccineName, - style: TextStyle( - fontSize: 17.0, - ), - ), - SizedBox(height: 7.0), - Text( - 'Date Taken ' + - convertDateFormat(model - .vaccineList[index] - .invoiceDate), - style: TextStyle( - fontSize: 17.0), + fontSize: 16.6, + ), + ), + SizedBox(height: 7.0), + Text( + model + .vaccineList[ + index] + .projectName, + style: TextStyle( + fontSize: 17.0, + letterSpacing: 0.5, + ), + ), + SizedBox(height: 7.0), + Text( + model + .vaccineList[ + index] + .vaccineName, + style: TextStyle( + fontSize: 17.0, + ), + ), + SizedBox(height: 7.0), + Text( + 'Date Taken ' + + convertDateFormat(model + .vaccineList[ + index] + .invoiceDate), + style: TextStyle( + fontSize: 17.0), + ), + ], ), - ], + ), + flex: 5, ), - ), - flex: 5, + ], ), ], ), - ], - ), - ), - ], - ); - }), - ) - ], - ), - ), - // SpaceBetweenTexts(space: 165.0), - ], - ), - ), - bottomSheet: Container( - color: Theme.of(context).scaffoldBackgroundColor, - padding: EdgeInsets.all(12), - height: MediaQuery.of(context).size.height * 0.25, - width: double.infinity, - child: Column( - children: [ - Divider( - height: 2, - thickness: 1, - ), - SizedBox( - height: 6, - ), - Container( - width: double.infinity, - // height: 80.0, - child: Button( - disabled: true, - label: TranslationBase.of(context).checkVaccineAvailability, - backgroundColor: Color(0xff9EA3A4), - onTap: () => Navigator.push( - context, FadePage(page: MyVaccinesItemPage())), - ), + ), + ], + ); + }), + ) + ], + ), + ), + // SpaceBetweenTexts(space: 165.0), + ], ), - if (projectViewModel.havePrivilege(27)) - Container( - width: double.infinity, - // height: 80.0, - child: SecondaryButton( - label: TranslationBase.of(context).sendEmail, - color: Color(0xffF62426), - textColor: Colors.white, - disabled: model.vaccineList.length == 0, - loading: model.state == ViewState.BusyLocal, - onTap: () async { - model.sendEmail( - message: TranslationBase.of(context) - .emailSentSuccessfully); - }, + ), + bottomSheet: model.state == ViewState.Busy?Container(height: 0,): model.vaccineList.length > 0 + ? Container( + color: Theme.of(context).scaffoldBackgroundColor, + padding: EdgeInsets.all(12), + height: MediaQuery.of(context).size.height * 0.25, + width: double.infinity, + child: Column( + children: [ + Divider( + height: 2, + thickness: 1, + ), + SizedBox( + height: 6, ), - ), - ], + Container( + width: double.infinity, + // height: 80.0, + child: Button( + disabled: true, + label: TranslationBase.of(context) + .checkVaccineAvailability, + backgroundColor: Color(0xff9EA3A4), + onTap: () => Navigator.push( + context, FadePage(page: MyVaccinesItemPage())), + ), + ), + if (projectViewModel.havePrivilege(27)) + Container( + width: double.infinity, + // height: 80.0, + child: SecondaryButton( + label: TranslationBase.of(context).sendEmail, + color: Color(0xffF62426), + textColor: Colors.white, + disabled: model.vaccineList.length == 0, + loading: model.state == ViewState.BusyLocal, + onTap: () async { + model.sendEmail( + message: TranslationBase.of(context) + .emailSentSuccessfully); + }, + ), + ), + ], + ), + ) + : Container(height: 0,), ), - ), - ), ); }