From 46d7e7ee14d4136225cce30268099b045e33a3d4 Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Mon, 1 Nov 2021 16:02:40 +0200 Subject: [PATCH] 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);