From bc91b9ad88c462099f279c59880477d5789968ff Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Sun, 31 Oct 2021 17:15:17 +0200 Subject: [PATCH 1/2] bottom nav pharmacy --- .../viewModels/PharmacyPagesViewModel.dart | 17 ++ lib/main.dart | 11 +- lib/pages/final_products_page.dart | 75 ++++-- lib/pages/landing/landing_page_pharmcy.dart | 122 +-------- lib/pages/parent_categorise_page.dart | 150 ++++++----- lib/pages/pharmacies/product-brands.dart | 185 ++++++------- .../screens/cart-page/cart-order-page.dart | 4 +- .../screens/pharmacy_module_page.dart | 58 ++-- lib/pages/pharmacies/search_brands_page.dart | 21 +- lib/pages/pharmacy/profile/profile.dart | 9 +- lib/pages/pharmacy_categorise.dart | 4 + lib/widgets/others/app_scaffold_widget.dart | 247 ++++++++++++++---- .../pharmacy/bottom_nav_pharmacy_bar.dart | 2 +- .../bottom_nav_pharmacy_home_item.dart | 3 +- 14 files changed, 506 insertions(+), 402 deletions(-) create mode 100644 lib/core/viewModels/PharmacyPagesViewModel.dart diff --git a/lib/core/viewModels/PharmacyPagesViewModel.dart b/lib/core/viewModels/PharmacyPagesViewModel.dart new file mode 100644 index 00000000..41c43066 --- /dev/null +++ b/lib/core/viewModels/PharmacyPagesViewModel.dart @@ -0,0 +1,17 @@ +import 'package:flutter/cupertino.dart'; + +class PharmacyPagesViewModel with ChangeNotifier { + int currentTab = 0; + PageController pageController; + + PharmacyPagesViewModel() { + pageController = PageController(keepPage: true); + } + changeCurrentTab(int tab) { + if (pageController.hasClients) { + currentTab = tab; + pageController.jumpToPage(tab); + notifyListeners(); + } + } +} diff --git a/lib/main.dart b/lib/main.dart index 87120231..12deb064 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:diplomaticquarterapp/analytics/google-analytics.dart'; +import 'package:diplomaticquarterapp/core/viewModels/PharmacyPagesViewModel.dart'; import 'package:diplomaticquarterapp/theme/theme_notifier.dart'; import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart'; import 'package:diplomaticquarterapp/routes.dart'; @@ -19,7 +20,6 @@ import 'locator.dart'; import 'pages/pharmacies/compare-list.dart'; import 'package:firebase_core/firebase_core.dart'; - void main() async { WidgetsFlutterBinding.ensureInitialized(); FirebaseApp defaultApp = await Firebase.initializeApp(); @@ -34,7 +34,6 @@ class MyApp extends StatefulWidget { } class _MyApp extends State { - @override void initState() { // ProjectViewModel projectProvider; @@ -52,7 +51,6 @@ class _MyApp extends State { .showNow(title: "Payload", subtitle: payload, payload: payload); }); - // final themeNotifier = Provider.of(context); precacheImage(AssetImage('assets/images/powerd-by.jpg'), context); return LayoutBuilder( @@ -62,6 +60,9 @@ class _MyApp extends State { SizeConfig().init(constraints, orientation); return MultiProvider( providers: [ + ChangeNotifierProvider( + create: (context) => PharmacyPagesViewModel(), + ), ChangeNotifierProvider( create: (context) => ProjectViewModel(), ), @@ -85,9 +86,7 @@ class _MyApp extends State { ], child: Consumer( builder: (context, projectProvider, child) => MaterialApp( - navigatorObservers: [ - GAnalytics.shared.navObserver() - ], + navigatorObservers: [GAnalytics.shared.navObserver()], navigatorKey: locator().navigatorKey, showSemanticsDebugger: false, title: 'Diplomatic Quarter App', diff --git a/lib/pages/final_products_page.dart b/lib/pages/final_products_page.dart index 854b66a6..3e8f35ed 100644 --- a/lib/pages/final_products_page.dart +++ b/lib/pages/final_products_page.dart @@ -11,6 +11,7 @@ import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/pr import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/StarRating.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_pharmacy_widget.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'; @@ -23,7 +24,7 @@ class FinalProductsPage extends StatefulWidget { final String id; final int productType; // 1 : default, 2 : manufacturer , 3 : recently viewed AuthenticatedUserObject authenticatedUserObject = - locator(); + locator(); FinalProductsPage({this.id, this.productType = 1}); @@ -79,9 +80,10 @@ class _FinalProductsPageState extends State { allowAny: true, builder: (BuildContext context, PharmacyCategoriseViewModel model, Widget child) => - PharmacyAppScaffold( + AppScaffold( + isPharmacy: true, appBarTitle: appBarTitle, - isBottomBar: false, + isBottomBar: true, isShowAppBar: true, backgroundColor: Colors.white, isShowDecPage: false, @@ -91,8 +93,6 @@ class _FinalProductsPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ -//Expanded widget heree if nassery - Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -613,30 +613,51 @@ class _FinalProductsPageState extends State { ], ), ), - - widget.authenticatedUserObject.isLogin + widget.authenticatedUserObject + .isLogin ? Container( - child: IconButton( - icon: Icon(Icons.shopping_cart, - size: 18, - color: Colors.blue,), - onPressed: () async { - if(model.finalProducts[index].rxMessage == null){ - GifLoaderDialogUtils.showMyDialog(context); - await addToCartFunction(1, model.finalProducts[index].id); - GifLoaderDialogUtils.hideDialog(context); - Navigator.push( - context, - FadePage(page: CartOrderPage())); - } - else{ - AppToast.showErrorToast(message: TranslationBase.of(context).needPrescription); - } + child: IconButton( + icon: Icon( + Icons + .shopping_cart, + size: 18, + color: + Colors.blue, + ), + onPressed: + () async { + if (model + .finalProducts[ + index] + .rxMessage == + null) { + GifLoaderDialogUtils + .showMyDialog( + context); + await addToCartFunction( + 1, + model + .finalProducts[ + index] + .id); + GifLoaderDialogUtils + .hideDialog( + context); + Navigator.push( + context, + FadePage( + page: + CartOrderPage())); + } else { + AppToast.showErrorToast( + message: TranslationBase.of( + context) + .needPrescription); + } // - } - - ), - ):Container(), + }), + ) + : Container(), ], ), ), diff --git a/lib/pages/landing/landing_page_pharmcy.dart b/lib/pages/landing/landing_page_pharmcy.dart index 6ae272e2..a71038e0 100644 --- a/lib/pages/landing/landing_page_pharmcy.dart +++ b/lib/pages/landing/landing_page_pharmcy.dart @@ -15,6 +15,7 @@ import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/pharmacy/bottom_nav_pharmacy_bar.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; @@ -27,24 +28,13 @@ class LandingPagePharmacy extends StatefulWidget { } class _LandingPagePharmacyState extends State { - int currentTab = 0; - PageController pageController; ProjectViewModel projectProvider; - _changeCurrentTab(int tab) { - setState(() { - currentTab = tab; - pageController.jumpToPage(tab); - }); - } - void initState() { super.initState(); locator().manufacturerList = []; locator().bestSellerProducts = []; locator().lastVisitedProducts = []; - - pageController = PageController(keepPage: true); } @override @@ -53,117 +43,15 @@ class _LandingPagePharmacyState extends State { onWillPop: () async { return false; }, - child: Scaffold( - appBar: currentTab != 4 && currentTab != 3 - ? AppBar( - backgroundColor: Color(0xff5AB145), - elevation: 0, - title: Container( - height: MediaQuery.of(context).size.height * 0.056, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.0), - color: Colors.white, - ), - child: InkWell( - child: Padding( - padding: EdgeInsets.all(5.0), - child: Row( - //crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(Icons.search, size: 25.0), - SizedBox( - width: 15.0, - ), - Texts( - TranslationBase.of(context).searchProductHere, - fontSize: 13, - ) - ], - ), - ), - onTap: () { - Navigator.push( - context, - FadePage(page: SearchProductsPage()), - ); - }, - ), - ), - leading: Builder( - builder: (BuildContext context) { - return InkWell( - onTap: () { - setState(() { - currentTab = 0; - pageController.jumpToPage(0); - }); - }, - child: Container( - height: 2.0, - width: 10.0, - child: Image.asset( - 'assets/images/pharmacy_logo.png', - ), - ), - ); - }, - ), - actions: [ - IconButton( - // iconSize: 70, - icon: Image.asset( - 'assets/images/new-design/qr-code.png', - ), - onPressed: _scanQrAndGetProduct //do something, - ) - ], - centerTitle: true, - ) - : null, + child: AppScaffold( + isBottomBar: true, extendBody: false, - body: PageView( - physics: NeverScrollableScrollPhysics(), - controller: pageController, - children: [ - PharmacyPage(), - PharmacyCategorisePage(), - PharmacyProfilePage(), - CartOrderPage(changeTab: _changeCurrentTab), - ], - ), - bottomNavigationBar: BottomNavPharmacyBar( - changeIndex: _changeCurrentTab, - index: currentTab, - ), + // isMainPharmacyPages: true, + body: null, ), ); } - void _scanQrAndGetProduct() async { - try { - String result = await BarcodeScanner.scan(); - try { - String barcode = result; - GifLoaderDialogUtils.showMyDialog(context); - await BaseAppClient() - .getPharmacy("$GET_PHARMACY_PRODUCTs_BY_SKU$barcode", - onSuccess: (dynamic response, int statusCode) { - print(response); - var product = PharmacyProduct.fromJson(response["products"][0]); - GifLoaderDialogUtils.hideDialog(context); - Navigator.push(context, FadePage(page: ProductDetailPage(product))); - }, onFailure: (String error, int statusCode) { - GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: "Product not found"); - }); - } catch (apiEx) { - AppToast.showErrorToast( - message: "Something went wrong, please try again"); - } - } catch (barcodeEx) {} - } - getText(currentTab) { switch (currentTab) { case 2: diff --git a/lib/pages/parent_categorise_page.dart b/lib/pages/parent_categorise_page.dart index 18133bb2..1a93a7b1 100644 --- a/lib/pages/parent_categorise_page.dart +++ b/lib/pages/parent_categorise_page.dart @@ -16,6 +16,7 @@ import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/StarRating.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_pharmacy_widget.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/others/entity_checkbox_list.dart'; import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; @@ -26,13 +27,12 @@ import 'package:provider/provider.dart'; import 'package:diplomaticquarterapp/pages/sub_categories_modalsheet.dart'; import 'base/base_view.dart'; - class ParentCategorisePage extends StatefulWidget { String id; String titleName; AuthenticatedUserObject authenticatedUserObject = - locator(); + locator(); ParentCategorisePage({this.id, this.titleName}); @@ -46,9 +46,11 @@ class _ParentCategorisePageState extends State { String titleName; final dynamic productID; - - - _ParentCategorisePageState({this.id, this.titleName, this.productID,}); + _ParentCategorisePageState({ + this.id, + this.titleName, + this.productID, + }); Map values = {'huusam': false, 'ali': false, 'noor': false}; bool checkedBrands = false; @@ -75,9 +77,10 @@ class _ParentCategorisePageState extends State { allowAny: true, builder: (BuildContext context, PharmacyCategoriseViewModel model, Widget child) => - PharmacyAppScaffold( + AppScaffold( + isPharmacy: true, appBarTitle: titleName, - isBottomBar: false, + isBottomBar: true, isShowAppBar: true, backgroundColor: Colors.white, isShowDecPage: false, @@ -139,8 +142,7 @@ class _ParentCategorisePageState extends State { page: SubCategoriseModalsheet( // id: model.categorise[0].id, // titleName: model.categorise[0].name, - ) - ), + )), ); // showModalBottomSheet( // isScrollControlled: true, @@ -348,13 +350,13 @@ class _ParentCategorisePageState extends State { width: 10.0, ), Texts( - - TranslationBase.of(context).refine, + TranslationBase.of( + context) + .refine, // 'Refine', fontWeight: FontWeight.w600, - ), SizedBox( width: 250.0, @@ -362,7 +364,9 @@ class _ParentCategorisePageState extends State { InkWell( child: Texts( // 'Close', - TranslationBase.of(context).closeIt, + TranslationBase.of( + context) + .closeIt, color: Colors.red, fontWeight: FontWeight.w600, @@ -383,10 +387,10 @@ class _ParentCategorisePageState extends State { Column( children: [ ExpansionTile( - - title: Texts( TranslationBase.of( - context) - .categorise), + title: Texts( + TranslationBase.of( + context) + .categorise), children: [ ProcedureListWidget( model: model, @@ -424,9 +428,10 @@ class _ParentCategorisePageState extends State { color: Colors.black12, ), ExpansionTile( - title: Texts( TranslationBase.of( - context) - .brands), + title: Texts( + TranslationBase.of( + context) + .brands), children: [ ProcedureListWidget( model: model, @@ -465,9 +470,10 @@ class _ParentCategorisePageState extends State { color: Colors.black12, ), ExpansionTile( - title: Texts( TranslationBase.of( - context) - .price), + title: Texts( + TranslationBase.of( + context) + .price), children: [ Container( color: Color( @@ -558,14 +564,11 @@ class _ParentCategorisePageState extends State { Container( width: 100, child: Button( - - label: TranslationBase.of( - context) + label: TranslationBase.of( + context) .reset, - backgroundColor: Colors.red, - - - + backgroundColor: + Colors.red, ), ), SizedBox( @@ -629,13 +632,12 @@ class _ParentCategorisePageState extends State { Navigator.pop( context); }, - - label: TranslationBase.of( - context) + label: TranslationBase.of( + context) .apply, - backgroundColor: Colors.green, - - + backgroundColor: + Colors + .green, ), ), ], @@ -1131,7 +1133,8 @@ class _ParentCategorisePageState extends State { padding: const EdgeInsets .only( - top: 4, bottom: 4), + top: 4, + bottom: 4), child: Texts( "SAR ${model.parentProducts[index].price}", bold: true, @@ -1167,30 +1170,50 @@ class _ParentCategorisePageState extends State { ], ), ), - - widget.authenticatedUserObject.isLogin ? - Container( - child: IconButton( - icon: Icon(Icons.shopping_cart, - size: 18, - color: Colors.blue,), - onPressed: () async { - if(model.parentProducts[index].rxMessage == null){ - GifLoaderDialogUtils.showMyDialog(context); - await addToCartFunction(1, model.parentProducts[index].id); - GifLoaderDialogUtils.hideDialog(context); - Navigator.push( - context, - FadePage(page: CartOrderPage())); - } - else{ - AppToast.showErrorToast(message: TranslationBase.of(context).needPrescription); - } - - } - - ), - ): Container(), + widget.authenticatedUserObject + .isLogin + ? Container( + child: IconButton( + icon: Icon( + Icons + .shopping_cart, + size: 18, + color: + Colors.blue, + ), + onPressed: + () async { + if (model + .parentProducts[ + index] + .rxMessage == + null) { + GifLoaderDialogUtils + .showMyDialog( + context); + await addToCartFunction( + 1, + model + .parentProducts[ + index] + .id); + GifLoaderDialogUtils + .hideDialog( + context); + Navigator.push( + context, + FadePage( + page: + CartOrderPage())); + } else { + AppToast.showErrorToast( + message: TranslationBase.of( + context) + .needPrescription); + } + }), + ) + : Container(), ], ), ), @@ -1238,8 +1261,6 @@ class _ParentCategorisePageState extends State { ), ), )); - - } addToCartFunction(quantity, itemID) async { @@ -1264,7 +1285,4 @@ class _ParentCategorisePageState extends State { } return false; } - - - } diff --git a/lib/pages/pharmacies/product-brands.dart b/lib/pages/pharmacies/product-brands.dart index fb3e38e4..fe04784b 100644 --- a/lib/pages/pharmacies/product-brands.dart +++ b/lib/pages/pharmacies/product-brands.dart @@ -35,105 +35,108 @@ class _ProductBrandsPageState extends State { isShowAppBar: true, isPharmacy: true, isShowDecPage: false, - body: Container( - child: Column( - children: [ - Container( - color: Colors.white, - alignment: - languageID == 'ar' ? Alignment.topRight : Alignment.topLeft, - padding: languageID == 'ar' - ? EdgeInsets.only(right: 10.0, top: 10.0) - : EdgeInsets.only(left: 10.0, top: 10.0), - child: Text( - TranslationBase.of(context).topBrands, - style: TextStyle( - fontWeight: FontWeight.bold, + body: SingleChildScrollView( + child: Container( + child: Column( + children: [ + Container( + color: Colors.white, + alignment: languageID == 'ar' + ? Alignment.topRight + : Alignment.topLeft, + padding: languageID == 'ar' + ? EdgeInsets.only(right: 10.0, top: 10.0) + : EdgeInsets.only(left: 10.0, top: 10.0), + child: Text( + TranslationBase.of(context).topBrands, + style: TextStyle( + fontWeight: FontWeight.bold, + ), ), ), - ), - Container( - height: 220, - width: double.infinity, - color: Colors.white, - child: topBrand(context), - ), - SizedBox( - height: 10, - ), - Container( - height: MediaQuery.of(context).size.height * 0.056, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.0), + Container( + height: 220, + width: double.infinity, color: Colors.white, + child: topBrand(context), ), - child: InkWell( - child: Padding( - padding: EdgeInsets.all(8.0), - child: Row( - //crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(Icons.search, size: 25.0), - SizedBox( - width: 15.0, - ), - Texts( - TranslationBase.of(context).searchProductHere, - fontSize: 13, - ) - ], + SizedBox( + height: 10, + ), + Container( + height: MediaQuery.of(context).size.height * 0.056, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5.0), + color: Colors.white, + ), + child: InkWell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: Row( + //crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Icon(Icons.search, size: 25.0), + SizedBox( + width: 15.0, + ), + Texts( + TranslationBase.of(context).searchProductHere, + fontSize: 13, + ) + ], + ), ), + onTap: () { + Navigator.push( + context, + FadePage(page: SearchBrandsPage()), + ); + }, ), - onTap: () { - Navigator.push( - context, - FadePage(page: SearchBrandsPage()), - ); - }, ), - ), - SizedBox( - height: 10, - ), - Container( - height: 420, - width: double.infinity, - color: Colors.white, - child: ListView.builder( - itemCount: model.brandsListList.length, - itemBuilder: (BuildContext context, int index) { - return InkWell( - child: Container( - margin: EdgeInsets.only(top: 50, left: 10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - languageID == 'ar' - ? Text(model.brandsListList[index].namen) - : Text(model.brandsListList[index].name), - SizedBox( - height: 3, - ), - Divider(height: 1, color: Colors.grey) - ], + SizedBox( + height: 10, + ), + Container( + height: 420, + width: double.infinity, + color: Colors.white, + child: ListView.builder( + itemCount: model.brandsListList.length, + itemBuilder: (BuildContext context, int index) { + return InkWell( + child: Container( + margin: EdgeInsets.only(top: 50, left: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + languageID == 'ar' + ? Text(model.brandsListList[index].namen) + : Text(model.brandsListList[index].name), + SizedBox( + height: 3, + ), + Divider(height: 1, color: Colors.grey) + ], + ), ), - ), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => FinalProductsPage( - id: model.brandsListList[index].id - .toString(), - )), - ); - }, - ); - }), - ), - ], + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => FinalProductsPage( + id: model.brandsListList[index].id + .toString(), + )), + ); + }, + ); + }), + ), + ], + ), ), ), ), diff --git a/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart b/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart index ef4904b2..5043b527 100644 --- a/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart +++ b/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart @@ -48,8 +48,10 @@ class _CartOrderPageState extends State { appBarTitle: TranslationBase.of(context).shoppingCart, isShowAppBar: true, isPharmacy: true, + isBottomBar: true, showHomeAppBarIcon: false, - isShowDecPage: true, + isShowDecPage: false, + isMainPharmacyPages: true, baseViewModel: model, backButtonTab: widget.changeTab != null ? () => widget.changeTab(0) : null, diff --git a/lib/pages/pharmacies/screens/pharmacy_module_page.dart b/lib/pages/pharmacies/screens/pharmacy_module_page.dart index 5ffe875c..0c88e473 100644 --- a/lib/pages/pharmacies/screens/pharmacy_module_page.dart +++ b/lib/pages/pharmacies/screens/pharmacy_module_page.dart @@ -21,36 +21,38 @@ class _PharmacyPageState extends State { Widget build(BuildContext context) { OrderPreviewViewModel orderPreviewViewModel = Provider.of(context); return WillPopScope( - onWillPop: ()async{ + onWillPop: () async { return false; }, - child:BaseView( - onModelReady: (model) async { - await model.getSavedLanguage(); - await model.getBannerList(); - if(model.isLogin) - await orderPreviewViewModel.getShoppingCart(); - }, - allowAny: true, - builder: (_, model, wi) => AppScaffold( - title: "", - isShowAppBar: false, - isShowDecPage: false, - baseViewModel: model, - backgroundColor: Colors.white, - body: Container( - width: double.infinity, - child: SingleChildScrollView( - child: Column( - //crossAxisAlignment: CrossAxisAlignment.start, - children: [ - BannerPager(model), - GridViewButtons(model), - PrescriptionsWidget(), - ShopByBrandWidget(), - RecentlyViewedWidget(), - BestSellerWidget(), - ],), + child: BaseView( + onModelReady: (model) async { + await model.getSavedLanguage(); + await model.getBannerList(); + if (model.isLogin) await orderPreviewViewModel.getShoppingCart(); + }, + allowAny: true, + builder: (_, model, wi) => AppScaffold( + title: "", + isShowDecPage: false, + baseViewModel: model, + isMainPharmacyPages: true, + isPharmacy: true, + isBottomBar: true, + backgroundColor: Colors.white, + body: Container( + width: double.infinity, + child: SingleChildScrollView( + child: Column( + //crossAxisAlignment: CrossAxisAlignment.start, + children: [ + BannerPager(model), + GridViewButtons(model), + PrescriptionsWidget(), + ShopByBrandWidget(), + RecentlyViewedWidget(), + BestSellerWidget(), + ], + ), ), ), ), diff --git a/lib/pages/pharmacies/search_brands_page.dart b/lib/pages/pharmacies/search_brands_page.dart index 8f771490..f053dee1 100644 --- a/lib/pages/pharmacies/search_brands_page.dart +++ b/lib/pages/pharmacies/search_brands_page.dart @@ -108,22 +108,23 @@ class _SearchBrandsPageState extends State { itemCount: model.searchList.length, itemBuilder: (BuildContext ctx, index) { return Padding( - padding:EdgeInsets.all(8.0), + padding: EdgeInsets.all(8.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Container( - child: Text( - model.searchList[index].name, - style: TextStyle(fontSize: 20), + Padding( + padding: const EdgeInsets.all(8.0), + child: Container( + child: Text( + model.searchList[index].name, + style: TextStyle(fontSize: 20), + ), ), ), - ), - Divider(height: 1, color: Colors.grey) - ],), + Divider(height: 1, color: Colors.grey) + ], + ), ); }, ), diff --git a/lib/pages/pharmacy/profile/profile.dart b/lib/pages/pharmacy/profile/profile.dart index a82a74eb..93c26844 100644 --- a/lib/pages/pharmacy/profile/profile.dart +++ b/lib/pages/pharmacy/profile/profile.dart @@ -94,11 +94,13 @@ class _ProfilePageState extends State { builder: (_, model, wi) => AppScaffold( appBarTitle: TranslationBase.of(context).myAccount, isShowAppBar: false, - isShowDecPage: false, + isShowDecPage: true, isPharmacy: true, + isBottomBar: true, + isMainPharmacyPages: true, body: user != null ? Container( - color: Colors.white, + color: Colors.white, child: SingleChildScrollView( child: Column( children: [ @@ -233,8 +235,7 @@ class _ProfilePageState extends State { Expanded( child: InkWell( onTap: () { - Navigator.push( - context, + Navigator.push(context, FadePage(page: WishlistPage())); }, child: Column( diff --git a/lib/pages/pharmacy_categorise.dart b/lib/pages/pharmacy_categorise.dart index b71c28ce..8dc357cb 100644 --- a/lib/pages/pharmacy_categorise.dart +++ b/lib/pages/pharmacy_categorise.dart @@ -35,6 +35,10 @@ class _PharmacyCategorisePageState extends State { Widget child) => AppScaffold( isShowDecPage: false, + isShowAppBar: false, + isMainPharmacyPages: true, + isPharmacy: true, + isBottomBar: true, baseViewModel: model, body: Column( children: [ diff --git a/lib/widgets/others/app_scaffold_widget.dart b/lib/widgets/others/app_scaffold_widget.dart index f80acf75..3d9d88b6 100644 --- a/lib/widgets/others/app_scaffold_widget.dart +++ b/lib/widgets/others/app_scaffold_widget.dart @@ -1,20 +1,32 @@ import 'package:badges/badges.dart'; +import 'package:barcode_scan_fix/barcode_scan.dart'; import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; +import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart'; +import 'package:diplomaticquarterapp/core/viewModels/PharmacyPagesViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/insurance/insurance_update_screen.dart'; import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-page/cart-order-page.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/screens/pharmacy_module_page.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; +import 'package:diplomaticquarterapp/pages/pharmacy/profile/profile.dart'; +import 'package:diplomaticquarterapp/pages/pharmacy_categorise.dart'; +import 'package:diplomaticquarterapp/pages/search_products_page.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/bottom_bar.dart'; +import 'package:diplomaticquarterapp/widgets/pharmacy/bottom_nav_pharmacy_bar.dart'; import 'package:diplomaticquarterapp/widgets/progress_indicator/app_loader_widget.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:diplomaticquarterapp/widgets/typewriter/typewiter.dart'; @@ -33,7 +45,9 @@ import 'not_auh_page.dart'; VoidCallback _onCartClick; -class AppScaffold extends StatelessWidget { +class AppScaffold extends StatefulWidget { + AppBarWidget appBar; + final String appBarTitle; final Widget body; final Widget bottomSheet; @@ -44,9 +58,11 @@ class AppScaffold extends StatelessWidget { final bool isBottomBar; final Widget floatingActionButton; final bool isPharmacy; + final bool isMainPharmacyPages; final bool isOfferPackages; final bool showPharmacyCart; final bool showOfferPackagesCart; + final bool extendBody; final String title; final String description; final bool isShowDecPage; @@ -60,12 +76,13 @@ class AppScaffold extends StatelessWidget { final bool isLocalLoader; final Function backButtonTab; - AuthenticatedUserObject authenticatedUserObject = - locator(); - - AppBarWidget appBar; final Widget customAppBar; + AppScaffold setOnAppBarCartClick(VoidCallback onClick) { + _onCartClick = onClick; + return this; + } + AppScaffold( {@required this.body, this.appBarTitle = '', @@ -76,13 +93,15 @@ class AppScaffold extends StatelessWidget { this.baseViewModel, this.floatingActionButton, this.isPharmacy = false, + this.isMainPharmacyPages = false, this.showPharmacyCart = true, this.isOfferPackages = false, this.showOfferPackagesCart = false, + this.extendBody = false, this.title, this.description, this.isShowDecPage = true, - this.isBottomBar, + this.isBottomBar = false, this.backgroundColor, this.preferredSize = 0.0, this.appBarIcons, @@ -95,56 +114,185 @@ class AppScaffold extends StatelessWidget { this.isLocalLoader = false, this.backButtonTab}); - AppScaffold setOnAppBarCartClick(VoidCallback onClick) { - _onCartClick = onClick; - return this; + @override + _AppScaffoldState createState() => _AppScaffoldState(); +} + +class _AppScaffoldState extends State { + AuthenticatedUserObject authenticatedUserObject = + locator(); + + @override + void initState() { + super.initState(); + } + + AppBar pharmacyAppbar() { + return Provider.of(context, listen: false) + .currentTab != + 4 && + Provider.of(context, listen: false) + .currentTab != + 3 + ? AppBar( + backgroundColor: Color(0xff5AB145), + elevation: 0, + title: Container( + height: MediaQuery.of(context).size.height * 0.056, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5.0), + color: Colors.white, + ), + child: InkWell( + child: Padding( + padding: EdgeInsets.all(5.0), + child: Row( + //crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Icon(Icons.search, size: 25.0), + SizedBox( + width: 15.0, + ), + Texts( + TranslationBase.of(context).searchProductHere, + fontSize: 13, + ) + ], + ), + ), + onTap: () { + Navigator.push( + context, + FadePage(page: SearchProductsPage()), + ); + }, + ), + ), + leading: Builder( + builder: (BuildContext context) { + return InkWell( + onTap: () { + Provider.of(context, listen: false) + .changeCurrentTab(0); + }, + child: Container( + height: 2.0, + width: 10.0, + child: Image.asset( + 'assets/images/pharmacy_logo.png', + ), + ), + ); + }, + ), + actions: [ + IconButton( + // iconSize: 70, + icon: Image.asset( + 'assets/images/new-design/qr-code.png', + ), + onPressed: _scanQrAndGetProduct //do something, + ) + ], + centerTitle: true, + ) + : null; } @override Widget build(BuildContext context) { + PharmacyPagesViewModel pagesViewModel = Provider.of(context); AppGlobal.context = context; return Scaffold( backgroundColor: - backgroundColor ?? Theme.of(context).scaffoldBackgroundColor, - appBar: isShowAppBar - ? customAppBar != null - ? customAppBar - : appBar = AppBarWidget( - appBarTitle: appBarTitle, - appBarIcons: appBarIcons, - showHomeAppBarIcon: showHomeAppBarIcon, - isPharmacy: isPharmacy, - showPharmacyCart: showPharmacyCart, - isOfferPackages: isOfferPackages, - showOfferPackagesCart: showOfferPackagesCart, - isShowDecPage: isShowDecPage, - backButtonTab: backButtonTab, - ) + widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor, + extendBody: widget.extendBody, + appBar: widget.isMainPharmacyPages + ? pharmacyAppbar() + : widget.isShowAppBar + ? widget.customAppBar != null + ? widget.customAppBar + : widget.appBar = AppBarWidget( + appBarTitle: widget.appBarTitle, + appBarIcons: widget.appBarIcons, + showHomeAppBarIcon: widget.showHomeAppBarIcon, + isPharmacy: widget.isPharmacy, + showPharmacyCart: widget.showPharmacyCart, + isOfferPackages: widget.isOfferPackages, + showOfferPackagesCart: widget.showOfferPackagesCart, + isShowDecPage: widget.isShowDecPage, + backButtonTab: widget.backButtonTab, + ) + : null, + bottomSheet: widget.bottomSheet, + body: (widget.isBottomBar && widget.isPharmacy) + ? PageView( + physics: NeverScrollableScrollPhysics(), + controller: pagesViewModel.pageController, + children: [ + PharmacyPage(), + PharmacyCategorisePage(), + PharmacyProfilePage(), + CartOrderPage(changeTab: pagesViewModel.changeCurrentTab), + ], + ) + : mainBody(), + floatingActionButton: widget.floatingActionButton, + bottomNavigationBar: widget.isBottomBar + ? BottomNavPharmacyBar( + changeIndex: pagesViewModel.changeCurrentTab, + index: pagesViewModel.currentTab, + ) : null, - bottomSheet: bottomSheet, - body: SafeArea( - top: true, - bottom: true, - child: - (!Provider.of(context, listen: false).isLogin && - isShowDecPage) - ? NotAutPage( - title: title ?? appBarTitle, - description: description, - infoList: infoList, - imagesInfo: imagesInfo, - ) - : baseViewModel != null - ? NetworkBaseView( - child: buildBodyWidget(context), - baseViewModel: baseViewModel, - ) - : buildBodyWidget(context), - ), - floatingActionButton: floatingActionButton, ); } + Widget mainBody() { + return SafeArea( + top: true, + bottom: true, + child: (!Provider.of(context, listen: false).isLogin && + widget.isShowDecPage) + ? NotAutPage( + title: widget.title ?? widget.appBarTitle, + description: widget.description, + infoList: widget.infoList, + imagesInfo: widget.imagesInfo, + ) + : widget.baseViewModel != null + ? NetworkBaseView( + child: buildBodyWidget(context), + baseViewModel: widget.baseViewModel, + ) + : buildBodyWidget(context), + ); + } + + void _scanQrAndGetProduct() async { + try { + String result = await BarcodeScanner.scan(); + try { + String barcode = result; + GifLoaderDialogUtils.showMyDialog(context); + await BaseAppClient() + .getPharmacy("$GET_PHARMACY_PRODUCTs_BY_SKU$barcode", + onSuccess: (dynamic response, int statusCode) { + print(response); + var product = PharmacyProduct.fromJson(response["products"][0]); + GifLoaderDialogUtils.hideDialog(context); + Navigator.push(context, FadePage(page: ProductDetailPage(product))); + }, onFailure: (String error, int statusCode) { + GifLoaderDialogUtils.hideDialog(context); + AppToast.showErrorToast(message: "Product not found"); + }); + } catch (apiEx) { + AppToast.showErrorToast( + message: "Something went wrong, please try again"); + } + } catch (barcodeEx) {} + } + buildAppLoaderWidget(bool isLoading) { return isLoading ? AppLoaderWidget() : Container(); } @@ -152,15 +300,15 @@ class AppScaffold extends StatelessWidget { buildBodyWidget(context) { return Stack(children: [ Center( - child: isLoading + child: widget.isLoading ? CircularProgressIndicator( backgroundColor: Colors.white, valueColor: AlwaysStoppedAnimation( Colors.grey[500], ), ) - : body), - isHelp == true ? RobotIcon() : Container() + : widget.body), + widget.isHelp == true ? RobotIcon() : Container() ]); } } @@ -263,7 +411,8 @@ class AppBarWidgetState extends State { icon: Badge( position: BadgePosition.topStart(top: -15, start: -10), badgeContent: Text( - orderPreviewViewModel.cartResponse.quantityCount.toString() /*_badgeText*/, + orderPreviewViewModel.cartResponse.quantityCount + .toString() /*_badgeText*/, style: TextStyle( fontSize: 9, color: Colors.white, diff --git a/lib/widgets/pharmacy/bottom_nav_pharmacy_bar.dart b/lib/widgets/pharmacy/bottom_nav_pharmacy_bar.dart index d1490d74..83ee640a 100644 --- a/lib/widgets/pharmacy/bottom_nav_pharmacy_bar.dart +++ b/lib/widgets/pharmacy/bottom_nav_pharmacy_bar.dart @@ -8,7 +8,7 @@ import 'bottom_nav_pharmacy_home_item.dart'; import 'bottom_nav_pharmacy_item.dart'; class BottomNavPharmacyBar extends StatefulWidget { - final ValueChanged changeIndex; + final Function changeIndex; final int index; BottomNavPharmacyBar({Key key, this.changeIndex, this.index}) : super(key: key); diff --git a/lib/widgets/pharmacy/bottom_nav_pharmacy_home_item.dart b/lib/widgets/pharmacy/bottom_nav_pharmacy_home_item.dart index 24986c74..6a930617 100644 --- a/lib/widgets/pharmacy/bottom_nav_pharmacy_home_item.dart +++ b/lib/widgets/pharmacy/bottom_nav_pharmacy_home_item.dart @@ -9,7 +9,7 @@ class BottomNavHomeItem extends StatelessWidget { final Image image; final String title; - final ValueChanged changeIndex; + final Function changeIndex; final int index; final int currentIndex; final Function onTap; @@ -62,7 +62,6 @@ class BottomNavHomeItem extends StatelessWidget { 'assets/images/habib-logo.png', ), height: 22.0, - ), SizedBox( height: 5, From 46d7e7ee14d4136225cce30268099b045e33a3d4 Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Mon, 1 Nov 2021 16:02:40 +0200 Subject: [PATCH 2/2] show bottom nav in pharmacy all pages --- lib/pages/landing/landing_page_pharmcy.dart | 37 +++- .../screens/cart-page/cart-order-page.dart | 2 +- .../screens/pharmacy_module_page.dart | 2 +- lib/pages/pharmacy/profile/profile.dart | 2 +- lib/pages/pharmacy_categorise.dart | 2 +- lib/widgets/others/app_scaffold_widget.dart | 179 ++++++++++-------- .../pharmacy/bottom_nav_pharmacy_bar.dart | 5 +- 7 files changed, 138 insertions(+), 91 deletions(-) diff --git a/lib/pages/landing/landing_page_pharmcy.dart b/lib/pages/landing/landing_page_pharmcy.dart index a71038e0..7a290383 100644 --- a/lib/pages/landing/landing_page_pharmcy.dart +++ b/lib/pages/landing/landing_page_pharmcy.dart @@ -3,6 +3,7 @@ import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart'; import 'package:diplomaticquarterapp/core/service/parmacyModule/parmacy_module_service.dart'; +import 'package:diplomaticquarterapp/core/viewModels/PharmacyPagesViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-page/cart-order-page.dart'; @@ -19,22 +20,42 @@ import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/pharmacy/bottom_nav_pharmacy_bar.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import '../../locator.dart'; class LandingPagePharmacy extends StatefulWidget { + final int currentTab; + + const LandingPagePharmacy({Key key, this.currentTab = 0}) : super(key: key); @override _LandingPagePharmacyState createState() => _LandingPagePharmacyState(); } class _LandingPagePharmacyState extends State { ProjectViewModel projectProvider; + int currentTab = 0; + PageController pageController; void initState() { super.initState(); locator().manufacturerList = []; locator().bestSellerProducts = []; locator().lastVisitedProducts = []; + pageController = + PageController(keepPage: true, initialPage: widget.currentTab); + setState(() { + currentTab = widget.currentTab; + }); + } + + changeCurrentTab(int tab) { + if (pageController.hasClients) { + setState(() { + currentTab = tab; + pageController.jumpToPage(tab); + }); + } } @override @@ -46,8 +67,20 @@ class _LandingPagePharmacyState extends State { child: AppScaffold( isBottomBar: true, extendBody: false, - // isMainPharmacyPages: true, - body: null, + isShowDecPage: false, + isMainPharmacyPages: true, + currentTab: currentTab, + changeCurrentTab: changeCurrentTab, + body: PageView( + physics: NeverScrollableScrollPhysics(), + controller: pageController, + children: [ + PharmacyPage(), + PharmacyCategorisePage(), + PharmacyProfilePage(), + CartOrderPage(changeTab: changeCurrentTab), + ], + ), ), ); } diff --git a/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart b/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart index 5043b527..31cfa666 100644 --- a/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart +++ b/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart @@ -48,7 +48,7 @@ class _CartOrderPageState extends State { appBarTitle: TranslationBase.of(context).shoppingCart, isShowAppBar: true, isPharmacy: true, - isBottomBar: true, + //isBottomBar: true, showHomeAppBarIcon: false, isShowDecPage: false, isMainPharmacyPages: true, diff --git a/lib/pages/pharmacies/screens/pharmacy_module_page.dart b/lib/pages/pharmacies/screens/pharmacy_module_page.dart index 0c88e473..77eca9c6 100644 --- a/lib/pages/pharmacies/screens/pharmacy_module_page.dart +++ b/lib/pages/pharmacies/screens/pharmacy_module_page.dart @@ -37,7 +37,7 @@ class _PharmacyPageState extends State { baseViewModel: model, isMainPharmacyPages: true, isPharmacy: true, - isBottomBar: true, + isShowPharmacyAppbar: true, backgroundColor: Colors.white, body: Container( width: double.infinity, diff --git a/lib/pages/pharmacy/profile/profile.dart b/lib/pages/pharmacy/profile/profile.dart index 93c26844..b9db9f29 100644 --- a/lib/pages/pharmacy/profile/profile.dart +++ b/lib/pages/pharmacy/profile/profile.dart @@ -96,7 +96,7 @@ class _ProfilePageState extends State { isShowAppBar: false, isShowDecPage: true, isPharmacy: true, - isBottomBar: true, + //isBottomBar: true, isMainPharmacyPages: true, body: user != null ? Container( diff --git a/lib/pages/pharmacy_categorise.dart b/lib/pages/pharmacy_categorise.dart index 8dc357cb..8a965b6e 100644 --- a/lib/pages/pharmacy_categorise.dart +++ b/lib/pages/pharmacy_categorise.dart @@ -38,7 +38,7 @@ class _PharmacyCategorisePageState extends State { isShowAppBar: false, isMainPharmacyPages: true, isPharmacy: true, - isBottomBar: true, + isShowPharmacyAppbar: true, baseViewModel: model, body: Column( children: [ diff --git a/lib/widgets/others/app_scaffold_widget.dart b/lib/widgets/others/app_scaffold_widget.dart index 3d9d88b6..6b8f42a3 100644 --- a/lib/widgets/others/app_scaffold_widget.dart +++ b/lib/widgets/others/app_scaffold_widget.dart @@ -13,6 +13,7 @@ import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreview import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/insurance/insurance_update_screen.dart'; import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; +import 'package:diplomaticquarterapp/pages/landing/landing_page_pharmcy.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-page/cart-order-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/pharmacy_module_page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; @@ -23,6 +24,7 @@ import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; +import 'package:diplomaticquarterapp/uitl/navigation_service.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/bottom_bar.dart'; @@ -75,9 +77,10 @@ class AppScaffold extends StatefulWidget { final bool isHelp; final bool isLocalLoader; final Function backButtonTab; - + final ValueChanged changeCurrentTab; final Widget customAppBar; - + final int currentTab; + final bool isShowPharmacyAppbar; AppScaffold setOnAppBarCartClick(VoidCallback onClick) { _onCartClick = onClick; return this; @@ -112,7 +115,10 @@ class AppScaffold extends StatefulWidget { appBar, this.customAppBar, this.isLocalLoader = false, - this.backButtonTab}); + this.backButtonTab, + this.changeCurrentTab, + this.currentTab, + this.isShowPharmacyAppbar = false}); @override _AppScaffoldState createState() => _AppScaffoldState(); @@ -128,76 +134,69 @@ class _AppScaffoldState extends State { } AppBar pharmacyAppbar() { - return Provider.of(context, listen: false) - .currentTab != - 4 && - Provider.of(context, listen: false) - .currentTab != - 3 - ? AppBar( - backgroundColor: Color(0xff5AB145), - elevation: 0, - title: Container( - height: MediaQuery.of(context).size.height * 0.056, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.0), - color: Colors.white, - ), - child: InkWell( - child: Padding( - padding: EdgeInsets.all(5.0), - child: Row( - //crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(Icons.search, size: 25.0), - SizedBox( - width: 15.0, - ), - Texts( - TranslationBase.of(context).searchProductHere, - fontSize: 13, - ) - ], - ), + return AppBar( + backgroundColor: Color(0xff5AB145), + elevation: 0, + title: Container( + height: MediaQuery.of(context).size.height * 0.056, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5.0), + color: Colors.white, + ), + child: InkWell( + child: Padding( + padding: EdgeInsets.all(5.0), + child: Row( + //crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Icon(Icons.search, size: 25.0), + SizedBox( + width: 15.0, ), - onTap: () { - Navigator.push( - context, - FadePage(page: SearchProductsPage()), - ); - }, + Texts( + TranslationBase.of(context).searchProductHere, + fontSize: 13, + ) + ], + ), + ), + onTap: () { + Navigator.push( + context, + FadePage(page: SearchProductsPage()), + ); + }, + ), + ), + leading: Builder( + builder: (BuildContext context) { + return InkWell( + onTap: () { + Provider.of(context, listen: false) + .changeCurrentTab(0); + }, + child: Container( + height: 2.0, + width: 10.0, + child: Image.asset( + 'assets/images/pharmacy_logo.png', ), ), - leading: Builder( - builder: (BuildContext context) { - return InkWell( - onTap: () { - Provider.of(context, listen: false) - .changeCurrentTab(0); - }, - child: Container( - height: 2.0, - width: 10.0, - child: Image.asset( - 'assets/images/pharmacy_logo.png', - ), - ), - ); - }, + ); + }, + ), + actions: [ + IconButton( + // iconSize: 70, + icon: Image.asset( + 'assets/images/new-design/qr-code.png', ), - actions: [ - IconButton( - // iconSize: 70, - icon: Image.asset( - 'assets/images/new-design/qr-code.png', - ), - onPressed: _scanQrAndGetProduct //do something, - ) - ], - centerTitle: true, - ) - : null; + onPressed: _scanQrAndGetProduct //do something, + ) + ], + centerTitle: true, + ); } @override @@ -208,7 +207,7 @@ class _AppScaffoldState extends State { backgroundColor: widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor, extendBody: widget.extendBody, - appBar: widget.isMainPharmacyPages + appBar: widget.isShowPharmacyAppbar ? pharmacyAppbar() : widget.isShowAppBar ? widget.customAppBar != null @@ -226,28 +225,42 @@ class _AppScaffoldState extends State { ) : null, bottomSheet: widget.bottomSheet, - body: (widget.isBottomBar && widget.isPharmacy) - ? PageView( - physics: NeverScrollableScrollPhysics(), - controller: pagesViewModel.pageController, - children: [ - PharmacyPage(), - PharmacyCategorisePage(), - PharmacyProfilePage(), - CartOrderPage(changeTab: pagesViewModel.changeCurrentTab), - ], + body: (!Provider.of(context, listen: false).isLogin && + widget.isShowDecPage) + ? NotAutPage( + title: widget.title ?? widget.appBarTitle, + description: widget.description, + infoList: widget.infoList, + imagesInfo: widget.imagesInfo, ) - : mainBody(), + : widget.baseViewModel != null + ? NetworkBaseView( + child: buildBodyWidget(context), + baseViewModel: widget.baseViewModel, + ) + : buildBodyWidget(context), floatingActionButton: widget.floatingActionButton, bottomNavigationBar: widget.isBottomBar ? BottomNavPharmacyBar( - changeIndex: pagesViewModel.changeCurrentTab, - index: pagesViewModel.currentTab, + changeIndex: changeCurrentTab, + index: widget.currentTab, ) : null, ); } + void changeCurrentTab(int value) { + if (widget.isMainPharmacyPages) { + widget.changeCurrentTab(value); + } else { + Navigator.pushAndRemoveUntil( + locator().navigatorKey.currentContext, + MaterialPageRoute( + builder: (context) => LandingPagePharmacy(currentTab: value)), + (Route r) => false); + } + } + Widget mainBody() { return SafeArea( top: true, diff --git a/lib/widgets/pharmacy/bottom_nav_pharmacy_bar.dart b/lib/widgets/pharmacy/bottom_nav_pharmacy_bar.dart index 83ee640a..19c90da7 100644 --- a/lib/widgets/pharmacy/bottom_nav_pharmacy_bar.dart +++ b/lib/widgets/pharmacy/bottom_nav_pharmacy_bar.dart @@ -8,8 +8,9 @@ import 'bottom_nav_pharmacy_home_item.dart'; import 'bottom_nav_pharmacy_item.dart'; class BottomNavPharmacyBar extends StatefulWidget { - final Function changeIndex; - final int index; + final ValueChanged changeIndex; + int index = 0; + BottomNavPharmacyBar({Key key, this.changeIndex, this.index}) : super(key: key);