11import 'package:easy_localization/easy_localization.dart' ;
22import 'package:flutter/material.dart' ;
33import 'package:flutter/widgets.dart' ;
4+ import 'package:wooapp/config/config.dart' ;
45import 'package:wooapp/config/theme.dart' ;
56import 'package:wooapp/screens/cart/cart_screen.dart' ;
67import 'package:wooapp/screens/catalog/catalog_screen.dart' ;
@@ -18,28 +19,27 @@ class HomeScreen extends StatefulWidget {
1819class HomeScreenState extends State <HomeScreen > {
1920 int _currentTab = 0 ;
2021 late List <Widget > _tabs;
22+ late List <BottomNavigationBarItem > _bottomItems;
2123
22- List < BottomNavigationBarItem > _bottomItems = [
24+ /* = [
2325 BottomNavigationBarItem(icon: Icon(Icons.home), label: tr('tab_home')),
2426 BottomNavigationBarItem(icon: Icon(Icons.dashboard_rounded), label: tr('tab_search')),
25-
26- // BottomNavigationBarItem(
27- // label: 'Icon',
28- // icon: Container(
29- // padding: EdgeInsets.fromLTRB(4,8,8,8),
30- // decoration: BoxDecoration(
31- // shape: BoxShape.circle,
32- // color: Colors.indigo,
33- // ),
34- // child: FlutterLogo(
35- // size: 38.0,
36- // ),
37- // ),
38- // ),
39-
27+ /*BottomNavigationBarItem(
28+ label: 'Icon',
29+ icon: Container(
30+ padding: EdgeInsets.fromLTRB(4,8,8,8),
31+ decoration: BoxDecoration(
32+ shape: BoxShape.circle,
33+ color: Colors.indigo,
34+ ),
35+ child: FlutterLogo(
36+ size: 38.0,
37+ ),
38+ ),
39+ ),*/
4040 BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: tr('tab_cart')),
4141 BottomNavigationBarItem(icon: Icon(Icons.account_box), label: tr('tab_profile')),
42- ];
42+ ];*/
4343
4444 void _openStore () {
4545 setState (() {
@@ -49,47 +49,74 @@ class HomeScreenState extends State<HomeScreen> {
4949
5050 @override
5151 void initState () {
52- super .initState ();
52+ _bottomItems = [
53+ if (WooAppConfig .featureHomepage)
54+ BottomNavigationBarItem (
55+ icon: Icon (Icons .home),
56+ label: tr ('tab_home' ),
57+ ),
58+ if (WooAppConfig .featureCatalog)
59+ BottomNavigationBarItem (
60+ icon: Icon (Icons .dashboard_rounded),
61+ label: tr ('tab_search' ),
62+ ),
63+ if (WooAppConfig .featureCart)
64+ BottomNavigationBarItem (
65+ icon: Icon (Icons .shopping_cart),
66+ label: tr ('tab_cart' ),
67+ ),
68+ if (WooAppConfig .featureProfile)
69+ BottomNavigationBarItem (
70+ icon: Icon (Icons .account_box),
71+ label: tr ('tab_profile' ),
72+ ),
73+ ];
5374 _tabs = [
54- FeaturedScreen (),
55- CatalogScreen (),
56- CartScreen (
57- shoppingCallback: () => _openStore (),
58- ),
59- ProfileScreen (),
75+ if (WooAppConfig .featureHomepage)
76+ FeaturedScreen (),
77+ if (WooAppConfig .featureCatalog)
78+ CatalogScreen (),
79+ if (WooAppConfig .featureCart)
80+ CartScreen (
81+ shoppingCallback: () => _openStore (),
82+ ),
83+ if (WooAppConfig .featureProfile)
84+ ProfileScreen (),
6085 ];
86+ super .initState ();
6187 }
6288
6389 @override
64- Widget build (BuildContext context) {
65- return Scaffold (
66- // body: _tabs[_currentTab],
67- body: IndexedStack (
68- children: _tabs,
69- index: _currentTab,
70- ),
71- bottomNavigationBar: BottomNavigationBar (
72- type: BottomNavigationBarType .fixed,
73- unselectedItemColor: WooAppTheme .colorBottomBarIconNonActive,
74- selectedItemColor: WooAppTheme .colorBottomBarIconActive,
75- backgroundColor: WooAppTheme .colorBottomBarBackground,
76- showSelectedLabels: false ,
77- showUnselectedLabels: false ,
90+ Widget build (BuildContext context) => Scaffold (
91+ body: IndexedStack (
92+ children: _tabs,
93+ index: _currentTab,
94+ ),
95+ bottomNavigationBar: _buildBottomNavigation (),
96+ );
7897
79- onTap: (index) {
80- setState (() {
81- _currentTab = index;
82- if (index == 2 ) {
83- (_tabs[2 ] as CartScreen ).refresh ();
84- }
85- if (index == 3 ) {
86- (_tabs[3 ] as ProfileScreen ).onTabOpened ();
87- }
88- });
89- },
90- currentIndex: _currentTab,
91- items: _bottomItems,
92- ),
98+ Widget ? _buildBottomNavigation () {
99+ if (_tabs.length < 2 ) return null ;
100+ return BottomNavigationBar (
101+ type: BottomNavigationBarType .fixed,
102+ unselectedItemColor: WooAppTheme .colorBottomBarIconNonActive,
103+ selectedItemColor: WooAppTheme .colorBottomBarIconActive,
104+ backgroundColor: WooAppTheme .colorBottomBarBackground,
105+ showSelectedLabels: false ,
106+ showUnselectedLabels: false ,
107+ onTap: (index) {
108+ setState (() {
109+ _currentTab = index;
110+ if (index == _tabs.indexWhere ((t) => t is CartScreen )) {
111+ (_tabs[index] as CartScreen ).refresh ();
112+ }
113+ if (index == _tabs.indexWhere ((t) => t is ProfileScreen )) {
114+ (_tabs[index] as ProfileScreen ).onTabOpened ();
115+ }
116+ });
117+ },
118+ currentIndex: _currentTab,
119+ items: _bottomItems,
93120 );
94121 }
95122}
0 commit comments