-
-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: #678 - added bottom navigation bar to product page #679
Merged
monsieurtanuki
merged 4 commits into
openfoodfacts:develop
from
monsieurtanuki:feature/#678
Nov 25, 2021
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
30e6841
feat: #678 - added bottom navigation bar to product page
monsieurtanuki 683dc9a
feat: #678 - explicitly selecting the bottom navigation tab
monsieurtanuki 49b21a6
feat: #678 - (forgot that one)
monsieurtanuki 5b51a2a
feat: #678 - renaming getCurrentPage to getDefaultPage
monsieurtanuki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/smooth_app/lib/pages/smooth_bottom_navigation_bar.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 getCurrentPage({ | ||
final SmoothBottomNavigationTab tab = _defaultTab, | ||
}) => | ||
_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) => _pages[_tabs[index]]!.body, | ||
), | ||
), | ||
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, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
packages/smooth_ui_library/lib/navigation/models/smooth_bottom_navigation_bar_item.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we only need to expose this method outside? it's only used in
main.dart
, maybe we can call itgetDefaultPage