From c76900a868592e5fd464a006317ab0916a04e144 Mon Sep 17 00:00:00 2001 From: RoaaGhali98 Date: Tue, 8 Feb 2022 16:21:36 +0200 Subject: [PATCH] Refactor add_prescription_form --- .../procedures/add-favourite-procedure.dart | 187 ++++++++--------- .../base_add_procedure_tab_page.dart | 191 +++++++----------- .../procedures/entity_list_fav_procedure.dart | 106 +++++----- 3 files changed, 207 insertions(+), 277 deletions(-) diff --git a/lib/screens/procedures/add-favourite-procedure.dart b/lib/screens/procedures/add-favourite-procedure.dart index e24af0b3..4df2726e 100644 --- a/lib/screens/procedures/add-favourite-procedure.dart +++ b/lib/screens/procedures/add-favourite-procedure.dart @@ -17,6 +17,7 @@ import 'package:flutter/material.dart'; import '../../config/config.dart'; import '../../widgets/shared/loader/gif_loader_dialog_utils.dart'; +import '../patients/profile/soap_update/shared_soap_widgets/bottom_sheet_dialog_button.dart'; import 'ProcedureType.dart'; class AddFavouriteProcedure extends StatefulWidget { @@ -48,110 +49,96 @@ class _AddFavouriteProcedureState extends State { @override Widget build(BuildContext context) { return BaseView( - builder: (BuildContext context, ProcedureViewModel model_, Widget child) => + builder: (BuildContext context, ProcedureViewModel model_, + Widget child) => AppScaffold( - isShowAppBar: false, - baseViewModel: model, - body: Column( - children: [ - Container( - height: MediaQuery.of(context).size.height * 0.070, - ), - (widget.previousProcedureViewModel.templateList.length != 0) - ? Expanded( - child: EntityListCheckboxSearchFavProceduresWidget( - isProcedure: - !(widget.procedureType == ProcedureType.PRESCRIPTION), - model: widget.previousProcedureViewModel, - removeFavProcedure: (item) { - setState(() { - entityList.remove(item); - }); - }, - addFavProcedure: (history) { - setState(() { - entityList.add(history); - }); - }, - isEntityFavListSelected: (master) => - isEntityListSelected(master), - groupProcedures: groupProcedures, - selectProcedures: (selectedProcedure) { - setState(() { - groupProcedures = selectedProcedure; - }); - }, - ), - ) - : Container( - child: Padding( - padding: EdgeInsets.symmetric(vertical: 50.0), - child: AppText('You Don\'t have favorite prescription'), - ), - ), - ], - ), - bottomSheet: Container( - margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5), - child: Wrap( - alignment: WrapAlignment.center, - children: [ - AppButton( - title: widget.procedureType.getAddButtonTitle(context) ?? - TranslationBase.of(context).addSelectedProcedures, - color: AppGlobal.appGreenColor, - disabled: widget.previousProcedureViewModel.templateList.length == 0 ? true : false, - fontWeight: FontWeight.w700, - onPressed: () { - if (widget.procedureType == ProcedureType.PRESCRIPTION) { - if (groupProcedures == null) { - DrAppToastMsg.showErrorToast( - 'Please Select item ', - ); - return; - } + isShowAppBar: false, + baseViewModel: model, + body: Column( + children: [ + (widget.previousProcedureViewModel.templateList.length != 0) + ? Expanded( + child: EntityListCheckboxSearchFavProceduresWidget( + isProcedure: !(widget.procedureType == + ProcedureType.PRESCRIPTION), + model: widget.previousProcedureViewModel, + removeFavProcedure: (item) { + setState(() { + entityList.remove(item); + }); + }, + addFavProcedure: (history) { + setState(() { + entityList.add(history); + }); + }, + isEntityFavListSelected: (master) => + isEntityListSelected(master), + groupProcedures: groupProcedures, + selectProcedures: (selectedProcedure) { + setState(() { + groupProcedures = selectedProcedure; + }); + }, + ), + ) + : Container( + child: Padding( + padding: EdgeInsets.symmetric(vertical: 50.0), + child: AppText( + 'You Don\'t have favorite prescription'), + ), + ), + ], + ), + bottomSheet: BottomSheetDialogButton( + label: widget.procedureType.getAddButtonTitle(context) ?? + TranslationBase.of(context).addSelectedProcedures, + onTap: () async { + if (widget.procedureType == ProcedureType.PRESCRIPTION) { + if (groupProcedures == null) { + DrAppToastMsg.showErrorToast( + 'Please Select item ', + ); + return; + } - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => PrescriptionCheckOutScreen( - patient: widget.patient, - model: widget.prescriptionModel, - groupProcedures: groupProcedures, - ), - settings: RouteSettings( - name: 'PrescriptionCheckOutScreen')), - ); - } else { - if (entityList.isEmpty == true) { - DrAppToastMsg.showErrorToast( - TranslationBase.of(context) - .fillTheMandatoryProcedureDetails, + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PrescriptionCheckOutScreen( + patient: widget.patient, + model: widget.prescriptionModel, + groupProcedures: groupProcedures, + ), + settings: RouteSettings( + name: 'PrescriptionCheckOutScreen')), + ); + } else { + if (entityList.isEmpty == true) { + DrAppToastMsg.showErrorToast( + TranslationBase.of(context) + .fillTheMandatoryProcedureDetails, + ); + return; + } + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ProcedureCheckOutScreen( + items: entityList, + model: model, + patient: widget.patient, + addButtonTitle: widget.procedureType + .getAddButtonTitle(context), + toolbarTitle: widget.procedureType + .getToolbarLabel(context), + ), + settings: + RouteSettings(name: 'ProcedureCheckOutScreen')), ); - return; } - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => ProcedureCheckOutScreen( - items: entityList, - model: model, - patient: widget.patient, - addButtonTitle: widget.procedureType - .getAddButtonTitle(context), - toolbarTitle: widget.procedureType - .getToolbarLabel(context), - ), - settings: - RouteSettings(name: 'ProcedureCheckOutScreen')), - ); - } - }, - ), - ], - ), - ), - ), + })), ); } diff --git a/lib/screens/procedures/base_add_procedure_tab_page.dart b/lib/screens/procedures/base_add_procedure_tab_page.dart index a3ea04f2..271baff9 100644 --- a/lib/screens/procedures/base_add_procedure_tab_page.dart +++ b/lib/screens/procedures/base_add_procedure_tab_page.dart @@ -82,105 +82,74 @@ class _BaseAddProcedureTabPageState extends State appBar: BottomSheetTitle(title: procedureType.getToolbarLabel(context),), body: NetworkBaseView( baseViewModel: model, - child: DraggableScrollableSheet( - minChildSize: 0.90, - initialChildSize: 0.95, - maxChildSize: 1.0, - builder: - (BuildContext context, ScrollController scrollController) { - return Container( - height: MediaQuery.of(context).size.height * 1.25, - child: Padding( - padding: EdgeInsets.all(12.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Scaffold( - extendBodyBehindAppBar: true, - appBar: PreferredSize( - preferredSize: Size.fromHeight( - MediaQuery.of(context).size.height * 0.070), - child: Container( - height: - MediaQuery.of(context).size.height * 0.070, - decoration: BoxDecoration( - border: Border( - bottom: BorderSide( - color: Theme.of(context).dividerColor, - width: 0.5), //width: 0.7 - ), - color: Colors.white), - child: Center( - child: TabBar( - isScrollable: false, - controller: _tabController, - indicatorColor: Colors.transparent, - indicatorWeight: 1.0, - indicatorSize: TabBarIndicatorSize.tab, - labelColor: Theme.of(context).primaryColor, - labelPadding: EdgeInsets.only( - top: 0, left: 0, right: 0, bottom: 0), - unselectedLabelColor: Colors.grey[800], - tabs: [ - tabWidget( - screenSize, - _activeTab == 0, - - procedureType - .getFavouriteTabName(context), - isFirst: true,context: context - ), - tabWidget( - screenSize, - _activeTab == 1, - procedureType.getAllLabelName(context), - isLast: true,context: context - ), - ], - ), - ), - ), - ), - body: Column( - children: [ - Expanded( - child: TabBarView( - physics: BouncingScrollPhysics(), - controller: _tabController, - children: [ - AddFavouriteProcedure( - previousProcedureViewModel: model, - prescriptionModel: - widget.prescriptionModel, - patient: patient, - procedureType: procedureType, - ), - if (widget.procedureType == - ProcedureType.PRESCRIPTION) - AddPrescriptionForm( - widget.prescriptionModel, - widget.patient, - widget.prescriptionModel.prescriptionList, - ) - else - AddProcedurePage( - model: this.model, - patient: patient, - procedureType: procedureType, - ), - ], - ), - ), - ], - ), + child: Expanded( + child: Scaffold( + extendBodyBehindAppBar: true, + appBar: PreferredSize( + preferredSize: Size.fromHeight( + MediaQuery.of(context).size.height * 0.070), + child: TabBar( + isScrollable: false, + controller: _tabController, + indicatorColor: Colors.transparent, + indicatorWeight: 1.0, + indicatorSize: TabBarIndicatorSize.tab, + labelColor: Theme.of(context).primaryColor, + labelPadding: EdgeInsets.only( + top: 0, left: 0, right: 0, bottom: 0), + unselectedLabelColor: Colors.grey[800], + tabs: [ + tabWidget( + screenSize, + _activeTab == 0, + + procedureType + .getFavouriteTabName(context), + isFirst: true,context: context + ), + tabWidget( + screenSize, + _activeTab == 1, + procedureType.getAllLabelName(context), + isLast: true,context: context + ), + ], + ), + ), + body: Column( + children: [ + Expanded( + child: TabBarView( + physics: BouncingScrollPhysics(), + controller: _tabController, + children: [ + AddFavouriteProcedure( + previousProcedureViewModel: model, + prescriptionModel: + widget.prescriptionModel, + patient: patient, + procedureType: procedureType, ), - ), - ], + if (widget.procedureType == + ProcedureType.PRESCRIPTION) + AddPrescriptionForm( + widget.prescriptionModel, + widget.patient, + widget.prescriptionModel.prescriptionList, + ) + else + AddProcedurePage( + model: this.model, + patient: patient, + procedureType: procedureType, + ), + ], + ), ), - ), - ); - }), + ], + ), + ), + ) ), ), ); @@ -210,32 +179,10 @@ class _BaseAddProcedureTabPageState extends State child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - AppText( - title, - fontSize: SizeConfig.textMultiplier * 1.5, - color: isActive ? Colors.white : Color(0xFF2B353E), - fontWeight: FontWeight.w700, - ), + + TabHelper.getTabText(title: title, isActive: isActive), if (counter != -1) - Container( - margin: EdgeInsets.all(4), - width: 15, - height: 15, - decoration: BoxDecoration( - color: isActive ? Colors.white : Color(0xFFD02127), - shape: BoxShape.circle, - ), - child: Center( - child: FittedBox( - child: AppText( - "$counter", - fontSize: SizeConfig.textMultiplier * 1.5, - color: !isActive ? Colors.white : Color(0xFFD02127), - fontWeight: FontWeight.w700, - ), - ), - ), - ), + TabHelper.getTabCounter(isActive: isActive, counter: counter) ], ), ), diff --git a/lib/screens/procedures/entity_list_fav_procedure.dart b/lib/screens/procedures/entity_list_fav_procedure.dart index 3fc6ca32..a9fa5ddf 100644 --- a/lib/screens/procedures/entity_list_fav_procedure.dart +++ b/lib/screens/procedures/entity_list_fav_procedure.dart @@ -78,63 +78,59 @@ class _EntityListCheckboxSearchFavProceduresWidgetState @override Widget build(BuildContext context) { - return Container( - child: Column( - children: [ - NetworkBaseView( - baseViewModel: widget.model, - child: Container( - height: MediaQuery.of(context).size.height * 0.60, - child: Center( - child: Container( - margin: EdgeInsets.only(top: 15), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - color: Colors.white), - child: ListView( - children: [ - TextFields( - hintText: 'Search Favourite templates', - suffixIcon: EvaIcons.search, - suffixIconColor: Color(0xff2B353E), - onChanged: (value) { - filterSearchResults(value); - }, - hasBorder: false, - ), - SizedBox( - height: 15, - ), - widget.model.templateList.length != 0 - ? Column( - children: - widget.model.templateList.map((historyInfo) { - return ExpansionProcedure( - procedureTempleteModel: historyInfo, - model: widget.model, - removeFavProcedure: widget.removeFavProcedure, - addFavProcedure: widget.addFavProcedure, - selectProcedures: widget.selectProcedures, - isEntityListSelected: - widget.isEntityListSelected, - isEntityFavListSelected: - widget.isEntityFavListSelected, - isProcedure: widget.isProcedure, - groupProcedures: widget.groupProcedures); - }).toList(), - ) - : Center( - child: Container( - child: AppText("Sorry , No Match", - color: AppGlobal.appRedColor), - ), - ) - ], + return SingleChildScrollView( + child: NetworkBaseView( + baseViewModel: widget.model, + child: Container( + height: MediaQuery.of(context).size.height * 0.90, + child: Center( + child: Container( + margin: EdgeInsets.only(top: 15), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + color: Colors.white), + child: ListView( + children: [ + TextFields( + hintText: 'Search Favourite templates', + suffixIcon: EvaIcons.search, + suffixIconColor: Color(0xff2B353E), + onChanged: (value) { + filterSearchResults(value); + }, + hasBorder: false, ), - )), + SizedBox( + height: 15, + ), + widget.model.templateList.length != 0 + ? Column( + children: + widget.model.templateList.map((historyInfo) { + return ExpansionProcedure( + procedureTempleteModel: historyInfo, + model: widget.model, + removeFavProcedure: widget.removeFavProcedure, + addFavProcedure: widget.addFavProcedure, + selectProcedures: widget.selectProcedures, + isEntityListSelected: + widget.isEntityListSelected, + isEntityFavListSelected: + widget.isEntityFavListSelected, + isProcedure: widget.isProcedure, + groupProcedures: widget.groupProcedures); + }).toList(), + ) + : Center( + child: Container( + child: AppText("Sorry , No Match", + color: AppGlobal.appRedColor), + ), + ) + ], ), - ), - ], + )), + ), ), ); }