Skip to content

Commit 3840725

Browse files
authored
Home screen refactor and stability improvements (#9)
1 parent da7bd65 commit 3840725

7 files changed

Lines changed: 594 additions & 556 deletions

File tree

lib/config/config.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
class WooAppConfig {
22
static const String currency = '\$';
33
static const int paginationLimit = 10;
4+
5+
static const bool featureHomepage = true;
6+
static const bool featureCatalog = true;
7+
static const bool featureCart = true;
8+
static const bool featureProfile = true;
9+
static const bool featureWishList = true;
410
}

lib/screens/home/home.dart

Lines changed: 79 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:easy_localization/easy_localization.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter/widgets.dart';
4+
import 'package:wooapp/config/config.dart';
45
import 'package:wooapp/config/theme.dart';
56
import 'package:wooapp/screens/cart/cart_screen.dart';
67
import 'package:wooapp/screens/catalog/catalog_screen.dart';
@@ -18,28 +19,27 @@ class HomeScreen extends StatefulWidget {
1819
class 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
}

lib/screens/profile/profile_view.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
77
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
88
import 'package:lottie/lottie.dart';
99
import 'package:shimmer_animation/shimmer_animation.dart';
10+
import 'package:wooapp/config/config.dart';
1011
import 'package:wooapp/config/theme.dart';
1112
import 'package:wooapp/model/customer_profile.dart';
1213
import 'package:wooapp/screens/auth/login.dart';
@@ -245,7 +246,7 @@ class ProfileView extends StatelessWidget {
245246
print('back, context = $context');
246247
}),
247248
),
248-
WooSection(
249+
if (WooAppConfig.featureWishList) WooSection(
249250
icon: FaIcon(
250251
FontAwesomeIcons.heart,
251252
color: WooAppTheme.colorCommonSectionForeground,

0 commit comments

Comments
 (0)