From a398ede172cf9d8dcbe75ad8280800bbf7aeaa21 Mon Sep 17 00:00:00 2001 From: mosazaid Date: Mon, 4 Oct 2021 16:16:44 +0300 Subject: [PATCH] fix bugs pharmacy home --- .../parmacyModule/prescription_service.dart | 23 +- lib/core/viewModels/base_view_model.dart | 5 + .../pharmacyModule/BestSellerViewModel.dart | 5 + .../pharmacyModule/BrandViewModel.dart | 29 + .../pharmacyModule/LastVisitedViewModel.dart | 25 + .../pharmacyModule/PrescriptionViewModel.dart | 30 + .../pharmacy_module_view_model.dart | 81 +- lib/locator.dart | 9 + lib/pages/landing/landing_page_pharmcy.dart | 2 +- .../screens/pharmacy_module_page.dart | 1025 +++++++++-------- lib/widgets/others/network_base_view.dart | 17 +- 11 files changed, 652 insertions(+), 599 deletions(-) create mode 100644 lib/core/viewModels/pharmacyModule/BestSellerViewModel.dart create mode 100644 lib/core/viewModels/pharmacyModule/BrandViewModel.dart create mode 100644 lib/core/viewModels/pharmacyModule/LastVisitedViewModel.dart create mode 100644 lib/core/viewModels/pharmacyModule/PrescriptionViewModel.dart diff --git a/lib/core/service/parmacyModule/prescription_service.dart b/lib/core/service/parmacyModule/prescription_service.dart index d81c125d..6b34255b 100644 --- a/lib/core/service/parmacyModule/prescription_service.dart +++ b/lib/core/service/parmacyModule/prescription_service.dart @@ -9,36 +9,15 @@ class PrescriptionService extends BaseService { bool isFinished = true; bool hasError = false; String errorMsg = ''; - String url = ""; List _prescriptionsList = List(); List get prescriptionsList => _prescriptionsList; -// Future getPrescription() async { -// hasError = false; -// url = PRESCRIPTION; -// print("Print PRESCRIPTION url" + url); -// await baseAppClient.get(url, -// onSuccess: (dynamic response, int statusCode) { -// _prescriptionsList.clear(); -// response['PatientPrescriptionList'].forEach((item) { -// _prescriptionsList.add(Prescriptions.fromJson(item)); -// }); -// print(_prescriptionsList.length); -// print(response); -// }, onFailure: (String error, int statusCode) { -// hasError = true; -// super.error = error; -// }); -// } Future getPrescription() async { - url = PRESCRIPTION; - print("Print PRESCRIPTION url" + url); hasError = false; Map body = Map(); body['isDentalAllowedBackend'] = false; - print("Print PRESCRIPTION url" + url); - await baseAppClient.post(url, + await baseAppClient.post(PRESCRIPTION, onSuccess: (dynamic response, int statusCode) { _prescriptionsList.clear(); response['PatientPrescriptionList'].forEach((prescriptions) { diff --git a/lib/core/viewModels/base_view_model.dart b/lib/core/viewModels/base_view_model.dart index aab267e9..338fd339 100644 --- a/lib/core/viewModels/base_view_model.dart +++ b/lib/core/viewModels/base_view_model.dart @@ -15,6 +15,7 @@ class BaseViewModel extends ChangeNotifier { ViewState get state => _state; String error = ""; + String languageID = "en"; AuthenticatedUser user; AppSharedPreferences sharedPref = AppSharedPreferences(); @@ -51,6 +52,10 @@ class BaseViewModel extends ChangeNotifier { notifyListeners(); } + Future getSavedLanguage() async { + languageID = await sharedPref.getString(APP_LANGUAGE); + } + @override void dispose() { removeListener(() {}); diff --git a/lib/core/viewModels/pharmacyModule/BestSellerViewModel.dart b/lib/core/viewModels/pharmacyModule/BestSellerViewModel.dart new file mode 100644 index 00000000..8b28f7d7 --- /dev/null +++ b/lib/core/viewModels/pharmacyModule/BestSellerViewModel.dart @@ -0,0 +1,5 @@ +import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; + +class BestSellerViewModel extends BaseViewModel { + +} \ No newline at end of file diff --git a/lib/core/viewModels/pharmacyModule/BrandViewModel.dart b/lib/core/viewModels/pharmacyModule/BrandViewModel.dart new file mode 100644 index 00000000..8ffc057a --- /dev/null +++ b/lib/core/viewModels/pharmacyModule/BrandViewModel.dart @@ -0,0 +1,29 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/Manufacturer.dart'; +import 'package:diplomaticquarterapp/core/service/parmacyModule/parmacy_module_service.dart'; +import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; + +import '../../../locator.dart'; + +class BrandViewModel extends BaseViewModel { + PharmacyModuleService _pharmacyService = locator(); + + List get manufacturerList => _pharmacyService.manufacturerList; + + Future getTopManufacturerList() async { + setState(ViewState.Busy); + await _pharmacyService.getTopManufacturerList(); + if (_pharmacyService.hasError) { + error = _pharmacyService.error; + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + } + } + + @override + void dispose() { + + super.dispose(); + } +} diff --git a/lib/core/viewModels/pharmacyModule/LastVisitedViewModel.dart b/lib/core/viewModels/pharmacyModule/LastVisitedViewModel.dart new file mode 100644 index 00000000..efc628d6 --- /dev/null +++ b/lib/core/viewModels/pharmacyModule/LastVisitedViewModel.dart @@ -0,0 +1,25 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; +import 'package:diplomaticquarterapp/core/service/parmacyModule/parmacy_module_service.dart'; +import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; + +import '../../../locator.dart'; + +class LastVisitedViewModel extends BaseViewModel { + + PharmacyModuleService _pharmacyService = locator(); + + List get lastVisitedProducts => + _pharmacyService.lastVisitedProducts; + + getLastVisitedProducts() async { + setState(ViewState.Busy); + await _pharmacyService.getLastVisitedProducts(); + if (_pharmacyService.hasError) { + error = _pharmacyService.error; + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + } + } +} \ No newline at end of file diff --git a/lib/core/viewModels/pharmacyModule/PrescriptionViewModel.dart b/lib/core/viewModels/pharmacyModule/PrescriptionViewModel.dart new file mode 100644 index 00000000..69caa40f --- /dev/null +++ b/lib/core/viewModels/pharmacyModule/PrescriptionViewModel.dart @@ -0,0 +1,30 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/Prescriptions.dart'; +import 'package:diplomaticquarterapp/core/service/parmacyModule/prescription_service.dart'; +import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; +import 'package:provider/provider.dart'; + +import '../../../locator.dart'; +import '../project_view_model.dart'; + +class PrescriptionViewModel extends BaseViewModel { + + PrescriptionService _prescriptionService = locator(); + + List get prescriptionsList => + _prescriptionService.prescriptionsList; + + getPrescription() async { + await getSavedLanguage(); + +/* + setState(ViewState.Busy); + await _prescriptionService.getPrescription(); + if (_prescriptionService.hasError) { + error = _prescriptionService.error; + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + }*/ + } +} \ No newline at end of file diff --git a/lib/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart b/lib/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart index 072ef4c9..245841e6 100644 --- a/lib/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart +++ b/lib/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart @@ -19,36 +19,26 @@ class PharmacyModuleViewModel extends BaseViewModel { PharmacyModuleService _pharmacyService = locator(); - PrescriptionService _prescriptionService = locator(); - - dynamic languageID = "en"; - RecommendedProductService _recommendedProductService = locator(); List get bannerList => _pharmacyService.bannerItems; - List get manufacturerList => _pharmacyService.manufacturerList; - List get bestSellerProduct => _pharmacyService.bestSellerProducts; - List get lastVisitedProducts => - _pharmacyService.lastVisitedProducts; - List get recommendedProductList => _recommendedProductService.recommendedList; -// List> get recommendedProductList => -// _recommendedProductService.recommendedList; - - List get prescriptionsList => - _prescriptionService.prescriptionsList; - - bool hasError = false; -// List get pharmacyPrescriptionsList => PharmacyProduct.pharmacyPrescriptionsList ; - Future getLanguageID() async { - languageID = await sharedPref.getString(APP_LANGUAGE); + Future getBannerList() async { + setState(ViewState.BusyLocal); + await _pharmacyService.getBannerListList(); + if (_pharmacyService.hasError) + //{ + error = _pharmacyService.error; + // setState(ViewState.Error); + // }else + // setState(ViewState.Idle); } Future getPharmacyHomeData() async { @@ -64,11 +54,7 @@ class PharmacyModuleViewModel extends BaseViewModel { if (_pharmacyService.hasError) { error = _pharmacyService.error; setState(ViewState.Error); - } else { - await getBannerList(); } - } else { - await getBannerList(); } } @@ -82,7 +68,6 @@ class PharmacyModuleViewModel extends BaseViewModel { setState(ViewState.Idle); } } - Future generatePharmacyToken() async { setState(ViewState.Busy); await _pharmacyService.generatePharmacyToken(); @@ -94,16 +79,6 @@ class PharmacyModuleViewModel extends BaseViewModel { } } - Future getBannerList() async { - setState(ViewState.Busy); - await _pharmacyService.getBannerListList(); - if (_pharmacyService.hasError) { - error = _pharmacyService.error; - setState(ViewState.Error); - } else { - _getTopManufacturerList(); - } - } List getBannerImagesUrl() { List images = List(); @@ -115,40 +90,18 @@ class PharmacyModuleViewModel extends BaseViewModel { return images; } - _getTopManufacturerList() async { - await _pharmacyService.getTopManufacturerList(); - if (_pharmacyService.hasError) { - error = _pharmacyService.error; - setState(ViewState.Error); - } else { - setState(ViewState.Idle); - _getBestSellerProducts(); - } - } - - _getBestSellerProducts() async { + getBestSellerProducts() async { await _pharmacyService.getBestSellerProducts(); if (_pharmacyService.hasError) { error = _pharmacyService.error; setState(ViewState.Error); } else { - _getLastVisitedProducts(); } } - _getLastVisitedProducts() async { - await _pharmacyService.getLastVisitedProducts(); - if (_pharmacyService.hasError) { - error = _pharmacyService.error; - setState(ViewState.Error); - } else { - setState(ViewState.Idle); - } - } - //////////////////////////////////////////RecommendedProducts + getRecommendedProducts(productId) async { - hasError = false; setState(ViewState.Busy); await _recommendedProductService.getRecommendedProducts(productId); if (_recommendedProductService.hasError) { @@ -173,18 +126,6 @@ class PharmacyModuleViewModel extends BaseViewModel { } } - getPrescription() async { - print("Print PRESCRIPTION url"); - setState(ViewState.Busy); - await _prescriptionService.getPrescription(); - if (_prescriptionService.hasError) { - error = _prescriptionService.error; - setState(ViewState.Error); - } else { - setState(ViewState.Idle); - } - } - ///////////////////////or // getPrescriptions() async { diff --git a/lib/locator.dart b/lib/locator.dart index 92c6bf63..b855e5a7 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -120,6 +120,10 @@ import 'core/viewModels/pharmacies_view_model.dart'; import 'core/service/pharmacies_service.dart'; import 'core/service/insurance_service.dart'; import 'core/viewModels/insurance_card_View_model.dart'; +import 'core/viewModels/pharmacyModule/BestSellerViewModel.dart'; +import 'core/viewModels/pharmacyModule/BrandViewModel.dart'; +import 'core/viewModels/pharmacyModule/LastVisitedViewModel.dart'; +import 'core/viewModels/pharmacyModule/PrescriptionViewModel.dart'; import 'core/viewModels/pharmacyModule/brand_view_model.dart'; import 'core/viewModels/pharmacyModule/pharmacy_module_view_model.dart'; import 'core/viewModels/pharmacyModule/product_detail_view_model.dart'; @@ -302,6 +306,11 @@ void setupLocator() { locator.registerFactory(() => OffersCategoriseViewModel()); locator.registerFactory(() => BariatricsViewModel()); + locator.registerFactory(() => PrescriptionViewModel()); + locator.registerFactory(() => BrandViewModel()); + locator.registerFactory(() => BestSellerViewModel()); + locator.registerFactory(() => LastVisitedViewModel()); + // Offer And Packages //---------------------- locator.registerLazySingleton( diff --git a/lib/pages/landing/landing_page_pharmcy.dart b/lib/pages/landing/landing_page_pharmcy.dart index 5da853fb..ab0abe72 100644 --- a/lib/pages/landing/landing_page_pharmcy.dart +++ b/lib/pages/landing/landing_page_pharmcy.dart @@ -172,7 +172,7 @@ class _LandingPagePharmacyState extends State { .getPharmacy("$GET_PHARMACY_PRODUCTs_BY_SKU$barcode", onSuccess: (dynamic response, int statusCode) { print(response); - product = PharmacyProduct.fromJson(response["products"][0]); + var product = PharmacyProduct.fromJson(response["products"][0]); GifLoaderDialogUtils.hideDialog(context); Navigator.push(context, FadePage(page: ProductDetailPage(product))); }, onFailure: (String error, int statusCode) { diff --git a/lib/pages/pharmacies/screens/pharmacy_module_page.dart b/lib/pages/pharmacies/screens/pharmacy_module_page.dart index a5dc664c..d8d524e0 100644 --- a/lib/pages/pharmacies/screens/pharmacy_module_page.dart +++ b/lib/pages/pharmacies/screens/pharmacy_module_page.dart @@ -1,50 +1,46 @@ -import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; -import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; -import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_model.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/BrandViewModel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/LastVisitedViewModel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/PrescriptionViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/landing/home_page.dart'; import 'package:diplomaticquarterapp/pages/medical/prescriptions/prescriptions_home_page.dart'; import 'package:diplomaticquarterapp/pages/offers_categorise_page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/product-brands.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/product_detail.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/screens/lacum-activitaion-vida-page.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/screens/lakum-main-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/recommended-product-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/widgets/BannerPager.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/widgets/ProductTileItem.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/widgets/manufacturerItem.dart'; -import 'package:diplomaticquarterapp/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; +import 'package:provider/provider.dart'; import 'package:rating_bar/rating_bar.dart'; import '../../final_products_page.dart'; -import 'lacum-activitaion-vida-page.dart'; - -var product; class PharmacyPage extends StatefulWidget { - @override _PharmacyPageState createState() => _PharmacyPageState(); } class _PharmacyPageState extends State { - @override Widget build(BuildContext context) { return BaseView( onModelReady: (model) async { - await getLanguageID(); - await model.getPharmacyHomeData(); + // GifLoaderDialogUtils.showMyDialog(context); + await model.getSavedLanguage(); + await model.getBannerList(); + // GifLoaderDialogUtils.hideDialog(context); }, allowAny: true, builder: (_, model, wi) => AppScaffold( @@ -57,17 +53,21 @@ class _PharmacyPageState extends State { width: double.infinity, child: SingleChildScrollView( child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + //crossAxisAlignment: CrossAxisAlignment.start, children: [ BannerPager(model), GridViewButtons(model), + //PrescriptionsWidget(), + ShopByBrandWidget(), + RecentlyViewedWidget(), + // TODO MOUSA Container( margin: EdgeInsets.fromLTRB(10, 10, 10, 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Texts( - TranslationBase.of(context).myPrescription, + TranslationBase.of(context).bestSellers, bold: true, ), BorderedButton( @@ -77,235 +77,533 @@ class _PharmacyPageState extends State { textColor: Colors.green, vPadding: 6, hPadding: 4, - handler: () { + handler: () => { Navigator.push( - context, FadePage(page: HomePrescriptionsPage())); + context, + FadePage( + page: FinalProductsPage( + id: "", + //TODO Elham* handel this to understans form where the number comming + productType: 20, + ), + ), + ), }, ), ], ), ), Container( - height: model.prescriptionsList.length > 0 - ? MediaQuery.of(context).size.height * 0.28 - : 0, - padding: - EdgeInsets.symmetric(horizontal: 18.0, vertical: 14.0), -// height: MediaQuery.of(context).size.height * 0.28, -// width: 200.0, -// height: MediaQuery.of(context).size.height / 4 + 20, - margin: EdgeInsets.only(left: 10), - child: BaseView( - onModelReady: (model) => model.getPrescription(), - builder: (_, model, wi) => model.prescriptionsList.length != - 0 -// model.getPrescription(); - ? ListView.builder( - scrollDirection: Axis.horizontal, - shrinkWrap: true, - physics: ScrollPhysics(), - // physics: NeverScrollableScrollPhysics(), - itemCount: model.prescriptionsList.length, - itemBuilder: (context, index) { - return Container( -// width: 160.0, - height: - MediaQuery.of(context).size.height * 0.3, - padding: EdgeInsets.only( - bottom: 5.0, left: 5.0, right: 8.0), - margin: EdgeInsets.only(right: 10.0), - decoration: BoxDecoration( - border: Border.all( - color: Colors.grey, - style: BorderStyle.solid, - width: 1.0, - ), - color: Colors.white, - borderRadius: BorderRadius.circular(10.0)), - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, + height: MediaQuery.of(context).size.height / 4 + 20, + child: ListView.builder( + itemBuilder: (ctx, i) => + ProductTileItem(model.bestSellerProduct[i]), + scrollDirection: Axis.horizontal, + itemCount: model.bestSellerProduct.length, + ), + ), + ], + ), + ), + ), + ), + ); + } +} + +class GridViewButtons extends StatelessWidget { + final PharmacyModuleViewModel model; + + GridViewButtons(this.model); + + @override + Widget build(BuildContext context) { + final gridHeight = (MediaQuery.of(context).size.width * 0.3) * 1.8; + return Container( + child: SizedBox( + height: gridHeight, + child: GridView.count( + childAspectRatio: 2.2, + crossAxisSpacing: 10, + mainAxisSpacing: 10, + controller: new ScrollController(keepScrollOffset: false), + shrinkWrap: true, + padding: const EdgeInsets.all(4.0), + crossAxisCount: 2, + children: [ + DashboardItem( + imageName: 'pharmacy_module/bg_1.png', + hasColorFilter: false, + opacity: 0.8, + child: GridViewCard( + TranslationBase.of(context).offersAndPromotions, + 'assets/images/pharmacy_module/offer_icon.png', () { + Navigator.push(context, FadePage(page: OffersCategorisePage())); + }), + ), + DashboardItem( + imageName: 'pharmacy_module/bg_2.png', + opacity: 0, + hasColorFilter: false, + child: GridViewCard(TranslationBase.of(context).medicationRefill, + 'assets/images/pharmacy_module/medication_icon.png', () { + // model.checkUserIsActivated().then((isActivated) { + // if (isActivated) { + // Navigator.push(context, FadePage(page: LakumMainPage())); + // } else { + // Navigator.push( + // context, FadePage(page: LakumActivationVidaPage())); + // } + // }); + }), + ), + DashboardItem( + imageName: 'pharmacy_module/bg_3.png', + opacity: 0, + hasColorFilter: false, + child: GridViewCard(TranslationBase.of(context).myPrescriptions, + 'assets/images/pharmacy_module/prescription_icon.png', () { + Navigator.push( + context, FadePage(page: HomePrescriptionsPage())); + }), + ), + DashboardItem( + imageName: 'pharmacy_module/bg_4.png', + opacity: 0, + hasColorFilter: false, + child: GridViewCard( + TranslationBase.of(context).searchAndScanMedication, + 'assets/images/pharmacy_module/search_scan_icon.png', + () {}), + ), + ], + ), + ), + ); + } +} + +class GridViewCard extends StatelessWidget { + final String text; + final String cardImage; + final Function handler; + + GridViewCard(this.text, this.cardImage, this.handler); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.all(4.0), + child: Container( + child: Row( + children: [ + Expanded( + flex: 2, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + flex: 2, + child: Padding( + padding: const EdgeInsets.all(6), + child: Texts( + text, + color: Colors.white, + fontSize: SizeConfig.textMultiplier * 1.5, + ), + ), + ), + Row( + children: [ + BorderedButton( + TranslationBase.of(context).viewAll, + handler: handler, + tPadding: 0, + bPadding: 0, + ), + Expanded(child: Container()), + ], + ), + ], + ), + ), + Expanded( + child: Align( + alignment: Alignment.centerRight, + child: Image.asset( + cardImage, + fit: BoxFit.cover, + ), + ), + ), + ], + ), + ), + ); + } + + String getDate(String date) { + DateTime dateObj = DateUtil.convertStringToDate(date); + return DateUtil.getWeekDay(dateObj.weekday) + + ", " + + dateObj.day.toString() + + " " + + DateUtil.getMonth(dateObj.month) + + " " + + dateObj.year.toString(); + } +} + +class PrescriptionsWidget extends StatelessWidget { + @override + Widget build(BuildContext context) { + return BaseView( + onModelReady: (model) async { + if (Provider.of(context, listen: false).isLogin) { + model.getPrescription(); + } + }, + allowAny: true, + builder: (_, model, wi) => model.prescriptionsList.length != 0 + ? Container( + height: model.prescriptionsList.length > 0 + ? MediaQuery.of(context).size.height * 0.28 + : 0, + child: Column( + children: [ + Container( + margin: EdgeInsets.fromLTRB(10, 10, 10, 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + TranslationBase.of(context).myPrescription, + bold: true, + ), + BorderedButton( + TranslationBase.of(context).viewAll, + hasBorder: true, + borderColor: Colors.green, + textColor: Colors.green, + vPadding: 6, + hPadding: 4, + handler: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + HomePrescriptionsPage())); + }, + ), + ], + ), + ), + Container( + padding: + EdgeInsets.symmetric(horizontal: 18.0, vertical: 14.0), + margin: EdgeInsets.only(left: 10), + child: ListView.builder( + scrollDirection: Axis.horizontal, + shrinkWrap: true, + physics: ScrollPhysics(), + // physics: NeverScrollableScrollPhysics(), + itemCount: model.prescriptionsList.length, + itemBuilder: (context, index) { + return Container( + height: MediaQuery.of(context).size.height * 0.3, + padding: EdgeInsets.only( + bottom: 5.0, left: 5.0, right: 8.0), + margin: EdgeInsets.only(right: 10.0), + decoration: BoxDecoration( + border: Border.all( + color: Colors.grey, + style: BorderStyle.solid, + width: 1.0, + ), + color: Colors.white, + borderRadius: BorderRadius.circular(10.0)), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( children: [ - Row( - children: [ - Column(children: [ - Container( - padding: EdgeInsets.only( - top: 10.0, - left: 10.0, - right: 10.0, - bottom: 15.0, - ), - child: CircleAvatar( - radius: 30, - backgroundColor: - Colors.transparent, - child: Image.network( - model.prescriptionsList[index] - .doctorImageURL, - width: 60, - height: 60, - ), - ), + Column(children: [ + Container( + padding: EdgeInsets.only( + top: 10.0, + left: 10.0, + right: 10.0, + bottom: 15.0, + ), + child: CircleAvatar( + radius: 30, + backgroundColor: Colors.transparent, + child: Image.network( + model.prescriptionsList[index] + .doctorImageURL, + width: 60, + height: 60, ), - ]), -// Column( -// // crossAxisAlignment: CrossAxisAlignment.center, -// children: [ -// Container( -// margin: EdgeInsets.only(left: 1), -// padding: EdgeInsets.only( -// top: 10.0, -// left: 10.0, -// right: 3.0, -// bottom: 15.0, -// ), -// child: Image.network( -// model.prescriptionsList[index] -// .doctorImageURL, -// width: 60, -// height: 60, -// ), -// ), -// ]), - Column( -// crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - margin: - EdgeInsets.only(left: 1), - padding: EdgeInsets.only( - left: 15.0, right: 15.0), - decoration: BoxDecoration( - border: Border.all( - color: Colors.green, - style: - BorderStyle.solid, - width: 4.0, - ), - color: Colors.green, - borderRadius: - BorderRadius.circular( - 30.0)), - child: Text( - model.languageID == "ar" - ? model.prescriptionsList[index].isInOutPatientDescriptionN.toString() - : model.prescriptionsList[index].isInOutPatientDescription.toString(), - style: TextStyle( - color: Colors.white, - fontSize: 15.0, -// fontWeight: FontWeight.bold, - ), - )), - Row(children: [ - Image.asset( - 'assets/images/Icon-awesome-calendar.png', - width: 30, - height: 30, - ), - Text( - DateUtil.convertStringToDate( - model - .prescriptionsList[ - index] - .appointmentDate - .toString()) - .toString() - .substring(0, 10), - style: TextStyle( - color: Colors.black, - fontSize: 15.0, -// fontWeight: FontWeight.bold, - ), - ) - ]), - ], ), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ + ), + ]), + Column( + children: [ Container( - margin: EdgeInsets.only(left: 5), - child: Row(children: [ - Text( - model.prescriptionsList[index] - .doctorTitle - .toString(), - style: TextStyle( - color: Colors.black, - fontSize: 15.0, - fontWeight: FontWeight.bold, - ), - ), - Text( - model.prescriptionsList[index] - .doctorName - .toString(), + margin: EdgeInsets.only(left: 1), + padding: EdgeInsets.only( + left: 15.0, right: 15.0), + decoration: BoxDecoration( + border: Border.all( + color: Colors.green, + style: BorderStyle.solid, + width: 4.0, + ), + color: Colors.green, + borderRadius: + BorderRadius.circular( + 30.0)), + child: Text( + model.languageID == "ar" + ? model + .prescriptionsList[ + index] + .isInOutPatientDescriptionN + .toString() + : model + .prescriptionsList[ + index] + .isInOutPatientDescription + .toString(), style: TextStyle( - color: Colors.black, + color: Colors.white, fontSize: 15.0, - fontWeight: FontWeight.bold, ), - ), - ]), - ), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Container( - margin: EdgeInsets.only(left: 5), - child: Text( - model.prescriptionsList[index] - .clinicDescription - .toString(), + )), + Row(children: [ + Image.asset( + 'assets/images/Icon-awesome-calendar.png', + width: 30, + height: 30, + ), + Text( + DateUtil.convertStringToDate(model + .prescriptionsList[index] + .appointmentDate + .toString()) + .toString() + .substring(0, 10), style: TextStyle( - color: Colors.green, + color: Colors.black, fontSize: 15.0, -// fontWeight: FontWeight.bold, ), + ) + ]), + ], + ), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + margin: EdgeInsets.only(left: 5), + child: Row(children: [ + Text( + model.prescriptionsList[index] + .doctorTitle + .toString(), + style: TextStyle( + color: Colors.black, + fontSize: 15.0, + fontWeight: FontWeight.bold, ), ), - ], + Text( + model.prescriptionsList[index] + .doctorName + .toString(), + style: TextStyle( + color: Colors.black, + fontSize: 15.0, + fontWeight: FontWeight.bold, + ), + ), + ]), ), - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Container( - margin: EdgeInsets.only(left: 5), - child: Align( - alignment: Alignment.topLeft, - child: RatingBar.readOnly( - initialRating: model - .prescriptionsList[index] - .actualDoctorRate - .toDouble(), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + margin: EdgeInsets.only(left: 5), + child: Text( + model.prescriptionsList[index] + .clinicDescription + .toString(), + style: TextStyle( + color: Colors.green, + fontSize: 15.0, +// fontWeight: FontWeight.bold, + ), + ), + ), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + margin: EdgeInsets.only(left: 5), + child: Align( + alignment: Alignment.topLeft, + child: RatingBar.readOnly( + initialRating: model + .prescriptionsList[index] + .actualDoctorRate + .toDouble(), // initialRating: productRate, - size: 15.0, - filledColor: - Colors.yellow[700], - emptyColor: Colors.grey[500], - isHalfAllowed: true, - halfFilledIcon: - Icons.star_half, - filledIcon: Icons.star, - emptyIcon: Icons.star, - ), - ), - ) - ]), - ]), - ); - }) - : Container(), + size: 15.0, + filledColor: Colors.yellow[700], + emptyColor: Colors.grey[500], + isHalfAllowed: true, + halfFilledIcon: Icons.star_half, + filledIcon: Icons.star, + emptyIcon: Icons.star, + ), + ), + ) + ]), + ]), + ); + }), ), + ], + ), + ) + : Container(), + ); + } +} + +class ShopByBrandWidget extends StatelessWidget { + @override + Widget build(BuildContext context) { + return BaseView( + onModelReady: (model) => model.getTopManufacturerList(), + allowAny: true, + builder: (_, model, wi) => NetworkBaseView( + isLocalLoader: true, + baseViewModel: model, + child: Container( + child: Column( + children: [ + Container( + margin: EdgeInsets.fromLTRB(10, 10, 10, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + TranslationBase.of(context).shopByBrands, + bold: true, + ), + BorderedButton( + TranslationBase.of(context).viewAll, + hasBorder: true, + vPadding: 6, + hPadding: 4, + borderColor: Colors.green, + textColor: Colors.green, + handler: () => { + Navigator.push( + context, FadePage(page: ProductBrandsPage())), + }, + ), + ], + ), + ), + Container( + height: 100, + child: ListView.builder( + itemBuilder: (ctx, i) => + ManufacturerItem(model.manufacturerList[i]), + scrollDirection: Axis.horizontal, + itemCount: model.manufacturerList.length, + ), + ), + ], ), + ), + )); + } +} + +class RecentlyViewedWidget extends StatelessWidget { + @override + Widget build(BuildContext context) { + return BaseView( + onModelReady: (model) => model.getLastVisitedProducts(), + allowAny: true, + builder: (_, model, wi) => NetworkBaseView( + isLocalLoader: true, + baseViewModel: model, + child: Container( + child: Column( + children: [ + Container( + margin: EdgeInsets.fromLTRB(10, 10, 10, 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + TranslationBase.of(context).recentlyViewed, + bold: true, + ), + BorderedButton( + TranslationBase.of(context).viewAll, + hasBorder: true, + vPadding: 6, + hPadding: 4, + borderColor: Colors.green, + textColor: Colors.green, + handler: () { + Navigator.push( + context, + FadePage( + page: FinalProductsPage( + id: "", + productType: 3, + ), + ), + ); + }, + ), + ], + ), + ), + Container( + height: model.lastVisitedProducts.length > 0 + ? MediaQuery.of(context).size.height / 4 + 20 + : 0, + child: ListView.builder( + itemBuilder: (ctx, i) => + ProductTileItem(model.lastVisitedProducts[i]), + scrollDirection: Axis.horizontal, + itemCount: model.lastVisitedProducts.length, + ), + ), + ], + ), + ), + )); + } +} + // Container( // margin: EdgeInsets.fromLTRB(10, 10, 10, 10), // child: Row( @@ -538,284 +836,3 @@ class _PharmacyPageState extends State { // ), // ), // ), - Container( - margin: EdgeInsets.fromLTRB(10, 10, 10, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Texts( - TranslationBase.of(context).shopByBrands, - bold: true, - ), - BorderedButton( - TranslationBase.of(context).viewAll, - hasBorder: true, - vPadding: 6, - hPadding: 4, - borderColor: Colors.green, - textColor: Colors.green, - handler: () => { - Navigator.push( - context, FadePage(page: ProductBrandsPage())), - }, - ), - ], - ), - ), - Container( - height: 100, - child: ListView.builder( - itemBuilder: (ctx, i) => - ManufacturerItem(model.manufacturerList[i]), - scrollDirection: Axis.horizontal, - itemCount: model.manufacturerList.length, - ), - ), - Container( - margin: EdgeInsets.fromLTRB(10, 10, 10, 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Texts( - TranslationBase.of(context).recentlyViewed, - bold: true, - ), - BorderedButton( - TranslationBase.of(context).viewAll, - hasBorder: true, - vPadding: 6, - hPadding: 4, - borderColor: Colors.green, - textColor: Colors.green, - handler: () { - Navigator.push( - context, - FadePage( - page: FinalProductsPage( - id: "", - productType: 3, - ), - ), - ); - }, - ), - ], - ), - ), - Container( - height: model.lastVisitedProducts.length > 0 - ? MediaQuery.of(context).size.height / 4 + 20 - : 0, - child: ListView.builder( - itemBuilder: (ctx, i) => - ProductTileItem(model.lastVisitedProducts[i]), - scrollDirection: Axis.horizontal, - itemCount: model.lastVisitedProducts.length, - ), - ), - Container( - margin: EdgeInsets.fromLTRB(10, 10, 10, 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Texts( - TranslationBase.of(context).bestSellers, - bold: true, - ), - BorderedButton( - TranslationBase.of(context).viewAll, - hasBorder: true, - borderColor: Colors.green, - textColor: Colors.green, - vPadding: 6, - hPadding: 4, - handler: () => { - Navigator.push( - context, - FadePage( - page: FinalProductsPage( - id: "", - //TODO Elham* handel this to understans form where the number comming - productType: 20, - ), - ), - ), - }, - ), - ], - ), - ), - Container( - height: MediaQuery.of(context).size.height / 4 + 20, - child: ListView.builder( - itemBuilder: (ctx, i) => - ProductTileItem(model.bestSellerProduct[i]), - scrollDirection: Axis.horizontal, - itemCount: model.bestSellerProduct.length, - ), - ), - ], - ), - ), - ), - ), - ); - } - - addToWishlistFunction(itemID) async { - ProductDetailViewModel x = new ProductDetailViewModel(); - isInWishlist = true; - await x.addToWishlistData(itemID); - } - - deleteFromWishlistFunction(itemID) async { - ProductDetailViewModel x = new ProductDetailViewModel(); - isInWishlist = false; - await x.addToWishlistData(itemID); - } - -} - -class GridViewButtons extends StatelessWidget { - final PharmacyModuleViewModel model; - - GridViewButtons(this.model); - - @override - Widget build(BuildContext context) { - final gridHeight = (MediaQuery.of(context).size.width * 0.3) * 1.8; - return Container( - child: SizedBox( - height: gridHeight, - child: GridView.count( - childAspectRatio: 2.2, - crossAxisSpacing: 10, - mainAxisSpacing: 10, - controller: new ScrollController(keepScrollOffset: false), - shrinkWrap: true, - padding: const EdgeInsets.all(4.0), - crossAxisCount: 2, - children: [ - DashboardItem( - imageName: 'pharmacy_module/bg_1.png', - hasColorFilter: false, - opacity: 0.8, - child: GridViewCard( - TranslationBase.of(context).offersAndPromotions, - 'assets/images/pharmacy_module/offer_icon.png', () { - Navigator.push(context, FadePage(page: OffersCategorisePage())); - }), - ), - DashboardItem( - imageName: 'pharmacy_module/bg_2.png', - opacity: 0, - hasColorFilter: false, - child: GridViewCard(TranslationBase.of(context).medicationRefill, - 'assets/images/pharmacy_module/medication_icon.png', () { - model.checkUserIsActivated().then((isActivated) { - if (isActivated) { - Navigator.push(context, FadePage(page: LakumMainPage())); - } else { - Navigator.push( - context, FadePage(page: LakumActivationVidaPage())); - } - }); - }), - ), - DashboardItem( - imageName: 'pharmacy_module/bg_3.png', - opacity: 0, - hasColorFilter: false, - child: GridViewCard(TranslationBase.of(context).myPrescriptions, - 'assets/images/pharmacy_module/prescription_icon.png', () { - Navigator.push( - context, FadePage(page: PharmacyAddressesPage())); - }), - ), - DashboardItem( - imageName: 'pharmacy_module/bg_4.png', - opacity: 0, - hasColorFilter: false, - child: GridViewCard( - TranslationBase.of(context).searchAndScanMedication, - 'assets/images/pharmacy_module/search_scan_icon.png', - () {}), - ), - ], - ), - ), - ); - } -} - -class GridViewCard extends StatelessWidget { - final String text; - final String cardImage; - final Function handler; - - GridViewCard(this.text, this.cardImage, this.handler); - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.all(4.0), - child: Container( - child: Row( - children: [ - Expanded( - flex: 2, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - flex: 2, - child: Padding( - padding: const EdgeInsets.all(6), - child: Texts( - text, - color: Colors.white, - fontSize: SizeConfig.textMultiplier * 1.5, - ), - ), - ), - Row( - children: [ - BorderedButton( - TranslationBase.of(context).viewAll, - handler: handler, - tPadding: 0, - bPadding: 0, - ), - Expanded(child: Container()), - ], - ), - ], - ), - ), - Expanded( - child: Align( - alignment: Alignment.centerRight, - child: Image.asset( - cardImage, - fit: BoxFit.cover, - ), - ), - ), - ], - ), - ), - ); - } - - String getDate(String date) { - DateTime dateObj = DateUtil.convertStringToDate(date); - return DateUtil.getWeekDay(dateObj.weekday) + - ", " + - dateObj.day.toString() + - " " + - DateUtil.getMonth(dateObj.month) + - " " + - dateObj.year.toString(); - } -} \ No newline at end of file diff --git a/lib/widgets/others/network_base_view.dart b/lib/widgets/others/network_base_view.dart index bca942f4..7b4918bd 100644 --- a/lib/widgets/others/network_base_view.dart +++ b/lib/widgets/others/network_base_view.dart @@ -9,8 +9,9 @@ import 'package:flutter_gifimage/flutter_gifimage.dart'; class NetworkBaseView extends StatefulWidget { final BaseViewModel baseViewModel; final Widget child; + final bool isLocalLoader; - NetworkBaseView({Key key, this.baseViewModel, this.child}); + NetworkBaseView({Key key, this.baseViewModel, this.child, this.isLocalLoader = false}); @override _NetworkBaseViewState createState() => _NetworkBaseViewState(); @@ -42,7 +43,19 @@ class _NetworkBaseViewState extends State{ return widget.child; break; case ViewState.Busy: - return Container( + if(widget.isLocalLoader) + return Container( + height: 100, + child: Center( + child:CircularProgressIndicator( + backgroundColor: Colors.white, + valueColor: AlwaysStoppedAnimation( + Colors.red, + ), + ), + ), + ); + else return Container( height: MediaQuery.of(context).size.height, child: Stack(