Skip to content

Commit

Permalink
feat: #678 - added bottom navigation bar to product page (#679)
Browse files Browse the repository at this point in the history
The previous bottom navigation bottom bar was refactored, in order to be reused anywhere.
Then it was added to the product page.

Deleted files:
* `home_page.dart`
* `smooth_ui_library/smooth_bottom_navigation_bar.dart`
* `smooth_ui_library/smooth_bottom_navigation_bar_item.dart`

New file:
* `smooth_bottom_navigation_bar.dart`

Impacted files:
* `continuous_scan_page.dart`: added an explicit bottom navigation bar (was implicit through `HomePage`), explicitly on the "scan" tab
* `main.dart`: not using `HomePage` anymore; opens the "scan" page by default
* `new_product_page.dart`: added an explicit bottom navigation bar (was not there), implicitly on the "default" tab
* `product_list_page.dart`: added an explicit bottom navigation bar (was implicit through `HomePage`), explicitly on the "history" tab
* `product_page.dart`: added an explicit bottom navigation bar (was not there), implicitly on the "default" tab
* `smooth_ui_library.dart`: removed "UI" version of smooth bottom navigation bar
* `user_preferences_page.dart`:  added an explicit bottom navigation bar (was implicit through `HomePage`), explicitly on the "profile" tab
  • Loading branch information
monsieurtanuki authored Nov 25, 2021
1 parent 76222ac commit 212dd31
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 230 deletions.
4 changes: 2 additions & 2 deletions packages/smooth_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/search_history.dart';
import 'package:smooth_app/pages/home_page.dart';
import 'package:smooth_app/pages/smooth_bottom_navigation_bar.dart';
import 'package:smooth_app/themes/smooth_theme.dart';
import 'package:smooth_app/themes/theme_provider.dart';

Expand Down Expand Up @@ -171,7 +171,7 @@ class SmoothAppGetLanguage extends StatelessWidget {
DefaultAssetBundle.of(context),
languageCode,
);
return const HomePage();
return SmoothBottomNavigationBar.getDefaultPage();
}

Future<void> _refresh(
Expand Down
66 changes: 0 additions & 66 deletions packages/smooth_app/lib/pages/home_page.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:smooth_app/pages/personalized_ranking_page.dart';
import 'package:smooth_app/pages/product/common/product_list_dialog_helper.dart';
import 'package:smooth_app/pages/product/common/product_list_item.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
import 'package:smooth_app/pages/smooth_bottom_navigation_bar.dart';
import 'package:smooth_app/themes/smooth_theme.dart';

class ProductListPage extends StatefulWidget {
Expand Down Expand Up @@ -87,6 +88,9 @@ class _ProductListPageState extends State<ProductListPage> {
throw Exception('unknown list type ${productList.listType}');
}
return Scaffold(
bottomNavigationBar: const SmoothBottomNavigationBar(
tab: SmoothBottomNavigationTab.History,
),
appBar: AppBar(
backgroundColor: SmoothTheme.getColor(
colorScheme,
Expand Down
2 changes: 2 additions & 0 deletions packages/smooth_app/lib/pages/product/new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:smooth_app/helpers/launch_url_helper.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/product/common/product_dialog_helper.dart';
import 'package:smooth_app/pages/product/summary_card.dart';
import 'package:smooth_app/pages/smooth_bottom_navigation_bar.dart';
import 'package:smooth_app/themes/smooth_theme.dart';
import 'package:smooth_app/themes/theme_provider.dart';
import 'package:smooth_ui_library/util/ui_helpers.dart';
Expand Down Expand Up @@ -52,6 +53,7 @@ class _ProductPageState extends State<NewProductPage> {
final MaterialColor materialColor =
SmoothTheme.getMaterialColor(themeProvider);
return Scaffold(
bottomNavigationBar: const SmoothBottomNavigationBar(),
backgroundColor: SmoothTheme.getColor(
colorScheme,
materialColor,
Expand Down
2 changes: 2 additions & 0 deletions packages/smooth_app/lib/pages/product/product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:smooth_app/helpers/product_translation_helper.dart';
import 'package:smooth_app/pages/product/common/product_dialog_helper.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
import 'package:smooth_app/pages/product/new_product_page.dart';
import 'package:smooth_app/pages/smooth_bottom_navigation_bar.dart';
import 'package:smooth_app/pages/user_preferences_page.dart';
import 'package:smooth_app/themes/constant_icons.dart';
import 'package:smooth_app/themes/smooth_theme.dart';
Expand Down Expand Up @@ -106,6 +107,7 @@ class _ProductPageState extends State<ProductPage> {
}
}
return Scaffold(
bottomNavigationBar: const SmoothBottomNavigationBar(),
appBar: AppBar(
title: Text(_getProductName(appLocalizations)),
actions: <Widget>[
Expand Down
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/pages/scan/continuous_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:smooth_app/data_models/continuous_scan_model.dart';
import 'package:smooth_app/pages/personalized_ranking_page.dart';
import 'package:smooth_app/pages/smooth_bottom_navigation_bar.dart';
import 'package:smooth_app/widgets/smooth_product_carousel.dart';
import 'package:smooth_ui_library/smooth_ui_library.dart';
import 'package:smooth_ui_library/util/ui_helpers.dart';
Expand Down Expand Up @@ -33,6 +34,9 @@ class ContinuousScanPage extends StatelessWidget {
final double viewFinderBottomOffset = carouselHeight / 2.0;
return Scaffold(
appBar: AppBar(toolbarHeight: 0.0),
bottomNavigationBar: const SmoothBottomNavigationBar(
tab: SmoothBottomNavigationTab.Scan,
),
body: Stack(
children: <Widget>[
Container(
Expand Down
85 changes: 85 additions & 0 deletions packages/smooth_app/lib/pages/smooth_bottom_navigation_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
import 'package:smooth_app/pages/history_page.dart';
import 'package:smooth_app/pages/scan/scan_page.dart';
import 'package:smooth_app/pages/user_preferences_page.dart';

class _Page {
const _Page({required this.name, required this.icon, required this.body});
final String name;
final IconData icon;
final Widget body;
}

enum SmoothBottomNavigationTab {
Profile,
Scan,
History,
}

class SmoothBottomNavigationBar extends StatelessWidget {
const SmoothBottomNavigationBar({
this.tab = _defaultTab,
});

final SmoothBottomNavigationTab tab;

static const SmoothBottomNavigationTab _defaultTab =
SmoothBottomNavigationTab.Scan;

static const List<SmoothBottomNavigationTab> _tabs =
<SmoothBottomNavigationTab>[
SmoothBottomNavigationTab.Profile,
SmoothBottomNavigationTab.Scan,
SmoothBottomNavigationTab.History,
];

static const Map<SmoothBottomNavigationTab, _Page> _pages =
<SmoothBottomNavigationTab, _Page>{
SmoothBottomNavigationTab.Profile: _Page(
name: 'Profile', // TODO(monsieurtanuki): translate
icon: Icons.account_circle,
body: UserPreferencesPage(),
),
SmoothBottomNavigationTab.Scan: _Page(
name: 'Scan or Search',
icon: Icons.search,
body: ScanPage(),
),
SmoothBottomNavigationTab.History: _Page(
name: 'History',
icon: Icons.history,
body: HistoryPage(),
),
};

static Widget getDefaultPage() => _getTabPage(_defaultTab);

static Widget _getTabPage(final SmoothBottomNavigationTab tab) =>
_pages[tab]!.body;

@override
Widget build(BuildContext context) => BottomNavigationBar(
showSelectedLabels: false,
showUnselectedLabels: false,
selectedItemColor: Colors.white,
backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
currentIndex: _tabs.indexOf(tab),
onTap: (final int index) async => Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) => _getTabPage(_tabs[index]),
),
),
items: <BottomNavigationBarItem>[
_buildItem(_pages[_tabs[0]]!),
_buildItem(_pages[_tabs[1]]!),
_buildItem(_pages[_tabs[2]]!),
],
);

BottomNavigationBarItem _buildItem(final _Page page) =>
BottomNavigationBarItem(
icon: Icon(page.icon, size: 28),
label: page.name,
);
}
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/pages/user_preferences_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/pages/settings_page.dart';
import 'package:smooth_app/pages/smooth_bottom_navigation_bar.dart';
import 'package:smooth_app/themes/smooth_theme.dart';
import 'package:smooth_app/widgets/attribute_button.dart';

Expand Down Expand Up @@ -35,6 +36,9 @@ class UserPreferencesPage extends StatelessWidget {
final List<String> orderedImportantAttributeIds =
productPreferences.getOrderedImportantAttributeIds();
return Scaffold(
bottomNavigationBar: const SmoothBottomNavigationBar(
tab: SmoothBottomNavigationTab.Profile,
),
appBar: AppBar(
title: Text(appLocalizations.myPreferences),
actions: <Widget>[
Expand Down

This file was deleted.

Loading

0 comments on commit 212dd31

Please sign in to comment.