Skip to content

Commit

Permalink
Home screen refactor and stability improvements (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiftHackZ authored Feb 18, 2023
1 parent da7bd65 commit 3840725
Show file tree
Hide file tree
Showing 7 changed files with 594 additions and 556 deletions.
6 changes: 6 additions & 0 deletions lib/config/config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class WooAppConfig {
static const String currency = '\$';
static const int paginationLimit = 10;

static const bool featureHomepage = true;
static const bool featureCatalog = true;
static const bool featureCart = true;
static const bool featureProfile = true;
static const bool featureWishList = true;
}
131 changes: 79 additions & 52 deletions lib/screens/home/home.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:wooapp/config/config.dart';
import 'package:wooapp/config/theme.dart';
import 'package:wooapp/screens/cart/cart_screen.dart';
import 'package:wooapp/screens/catalog/catalog_screen.dart';
Expand All @@ -18,28 +19,27 @@ class HomeScreen extends StatefulWidget {
class HomeScreenState extends State<HomeScreen> {
int _currentTab = 0;
late List<Widget> _tabs;
late List<BottomNavigationBarItem> _bottomItems;

List<BottomNavigationBarItem> _bottomItems = [
/*= [
BottomNavigationBarItem(icon: Icon(Icons.home), label: tr('tab_home')),
BottomNavigationBarItem(icon: Icon(Icons.dashboard_rounded), label: tr('tab_search')),

// BottomNavigationBarItem(
// label: 'Icon',
// icon: Container(
// padding: EdgeInsets.fromLTRB(4,8,8,8),
// decoration: BoxDecoration(
// shape: BoxShape.circle,
// color: Colors.indigo,
// ),
// child: FlutterLogo(
// size: 38.0,
// ),
// ),
// ),

/*BottomNavigationBarItem(
label: 'Icon',
icon: Container(
padding: EdgeInsets.fromLTRB(4,8,8,8),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.indigo,
),
child: FlutterLogo(
size: 38.0,
),
),
),*/
BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: tr('tab_cart')),
BottomNavigationBarItem(icon: Icon(Icons.account_box), label: tr('tab_profile')),
];
];*/

void _openStore() {
setState(() {
Expand All @@ -49,47 +49,74 @@ class HomeScreenState extends State<HomeScreen> {

@override
void initState() {
super.initState();
_bottomItems = [
if (WooAppConfig.featureHomepage)
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: tr('tab_home'),
),
if (WooAppConfig.featureCatalog)
BottomNavigationBarItem(
icon: Icon(Icons.dashboard_rounded),
label: tr('tab_search'),
),
if (WooAppConfig.featureCart)
BottomNavigationBarItem(
icon: Icon(Icons.shopping_cart),
label: tr('tab_cart'),
),
if (WooAppConfig.featureProfile)
BottomNavigationBarItem(
icon: Icon(Icons.account_box),
label: tr('tab_profile'),
),
];
_tabs = [
FeaturedScreen(),
CatalogScreen(),
CartScreen(
shoppingCallback: () => _openStore(),
),
ProfileScreen(),
if (WooAppConfig.featureHomepage)
FeaturedScreen(),
if (WooAppConfig.featureCatalog)
CatalogScreen(),
if (WooAppConfig.featureCart)
CartScreen(
shoppingCallback: () => _openStore(),
),
if (WooAppConfig.featureProfile)
ProfileScreen(),
];
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
// body: _tabs[_currentTab],
body: IndexedStack(
children: _tabs,
index: _currentTab,
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
unselectedItemColor: WooAppTheme.colorBottomBarIconNonActive,
selectedItemColor: WooAppTheme.colorBottomBarIconActive,
backgroundColor: WooAppTheme.colorBottomBarBackground,
showSelectedLabels: false,
showUnselectedLabels: false,
Widget build(BuildContext context) => Scaffold(
body: IndexedStack(
children: _tabs,
index: _currentTab,
),
bottomNavigationBar: _buildBottomNavigation(),
);

onTap: (index) {
setState(() {
_currentTab = index;
if (index == 2) {
(_tabs[2] as CartScreen).refresh();
}
if (index == 3) {
(_tabs[3] as ProfileScreen).onTabOpened();
}
});
},
currentIndex: _currentTab,
items: _bottomItems,
),
Widget? _buildBottomNavigation() {
if (_tabs.length < 2) return null;
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
unselectedItemColor: WooAppTheme.colorBottomBarIconNonActive,
selectedItemColor: WooAppTheme.colorBottomBarIconActive,
backgroundColor: WooAppTheme.colorBottomBarBackground,
showSelectedLabels: false,
showUnselectedLabels: false,
onTap: (index) {
setState(() {
_currentTab = index;
if (index == _tabs.indexWhere((t) => t is CartScreen)) {
(_tabs[index] as CartScreen).refresh();
}
if (index == _tabs.indexWhere((t) => t is ProfileScreen)) {
(_tabs[index] as ProfileScreen).onTabOpened();
}
});
},
currentIndex: _currentTab,
items: _bottomItems,
);
}
}
3 changes: 2 additions & 1 deletion lib/screens/profile/profile_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:lottie/lottie.dart';
import 'package:shimmer_animation/shimmer_animation.dart';
import 'package:wooapp/config/config.dart';
import 'package:wooapp/config/theme.dart';
import 'package:wooapp/model/customer_profile.dart';
import 'package:wooapp/screens/auth/#.dart';
Expand Down Expand Up @@ -245,7 +246,7 @@ class ProfileView extends StatelessWidget {
print('back, context = $context');
}),
),
WooSection(
if (WooAppConfig.featureWishList) WooSection(
icon: FaIcon(
FontAwesomeIcons.heart,
color: WooAppTheme.colorCommonSectionForeground,
Expand Down
Loading

0 comments on commit 3840725

Please # to comment.