-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: first working stateful tab * feat: enum instead of String * Update tab_navigator.dart * feat: Working camera disable for other tabs * fix: #640 stop camera when navigating further in the stack * doc + null safety * fix: activating scanner when rebuilding from ground up * Updated goldens The navbar got removed from the images because it is now not directly added by the pages anymore * doc: * Minor changes * fix: Updating product with multiple navigators * Minor fixes * Simplification * Simplification * Simplification * Update main.dart * Update product_list_page.dart Co-authored-by: monsieurtanuki <[email protected]>
- Loading branch information
1 parent
692c817
commit ca3739e
Showing
18 changed files
with
201 additions
and
113 deletions.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:smooth_app/widgets/tab_navigator.dart'; | ||
|
||
enum BottomNavigationTab { | ||
Profile, | ||
Scan, | ||
History, | ||
} | ||
|
||
/// Here the different tabs in the bottom navigation bar are taken care of, | ||
/// so that they are stateful, that is not only things like the scroll position | ||
/// but also keeping the navigation on the different tabs. | ||
/// | ||
/// Scan Page is an exception here as it needs a little more work so that the | ||
/// camera is not kept unnecessarily kept active. | ||
class PageManager extends StatefulWidget { | ||
@override | ||
State<StatefulWidget> createState() => PageManagerState(); | ||
} | ||
|
||
class PageManagerState extends State<PageManager> { | ||
static const List<BottomNavigationTab> _pageKeys = <BottomNavigationTab>[ | ||
BottomNavigationTab.Profile, | ||
BottomNavigationTab.Scan, | ||
BottomNavigationTab.History, | ||
]; | ||
|
||
final Map<BottomNavigationTab, GlobalKey<NavigatorState>> _navigatorKeys = | ||
<BottomNavigationTab, GlobalKey<NavigatorState>>{ | ||
BottomNavigationTab.Profile: GlobalKey<NavigatorState>(), | ||
BottomNavigationTab.Scan: GlobalKey<NavigatorState>(), | ||
BottomNavigationTab.History: GlobalKey<NavigatorState>(), | ||
}; | ||
|
||
BottomNavigationTab _currentPage = BottomNavigationTab.Scan; | ||
|
||
void _selectTab(BottomNavigationTab tabItem, int index) { | ||
if (tabItem == _currentPage) { | ||
_navigatorKeys[tabItem]! | ||
.currentState! | ||
.popUntil((Route<dynamic> route) => route.isFirst); | ||
} else { | ||
setState(() { | ||
_currentPage = _pageKeys[index]; | ||
}); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return WillPopScope( | ||
onWillPop: () async { | ||
final bool isFirstRouteInCurrentTab = | ||
!await _navigatorKeys[_currentPage]!.currentState!.maybePop(); | ||
if (isFirstRouteInCurrentTab) { | ||
if (_currentPage != BottomNavigationTab.Scan) { | ||
_selectTab(BottomNavigationTab.Scan, 1); | ||
return false; | ||
} | ||
} | ||
// let system handle back button if we're on the first route | ||
return isFirstRouteInCurrentTab; | ||
}, | ||
child: Scaffold( | ||
body: Stack(children: <Widget>[ | ||
_buildOffstageNavigator(BottomNavigationTab.Profile), | ||
_buildOffstageNavigator(BottomNavigationTab.Scan), | ||
_buildOffstageNavigator(BottomNavigationTab.History), | ||
]), | ||
bottomNavigationBar: BottomNavigationBar( | ||
showSelectedLabels: false, | ||
showUnselectedLabels: false, | ||
selectedItemColor: Colors.white, | ||
backgroundColor: Theme.of(context).appBarTheme.backgroundColor, | ||
onTap: (int index) { | ||
_selectTab(_pageKeys[index], index); | ||
}, | ||
currentIndex: _currentPage.index, | ||
items: const <BottomNavigationBarItem>[ | ||
// TODO(M123): Translate | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.account_circle), | ||
label: 'Profile', | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.search), | ||
label: 'Scan or Search', | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.history), | ||
label: 'History', | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget _buildOffstageNavigator(BottomNavigationTab tabItem) { | ||
final bool offstage = _currentPage != tabItem; | ||
return Offstage( | ||
offstage: offstage, | ||
child: TabNavigator( | ||
offstage: offstage, | ||
navigatorKey: _navigatorKeys[tabItem]!, | ||
tabItem: tabItem, | ||
), | ||
); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,10 @@ import 'package:smooth_app/database/product_query.dart'; | |
import 'package:smooth_app/pages/scan/continuous_scan_page.dart'; | ||
|
||
class ScanPage extends StatefulWidget { | ||
const ScanPage(); | ||
const ScanPage({required this.offstage, required this.navigatorKey}); | ||
|
||
final bool offstage; | ||
final GlobalKey<NavigatorState> navigatorKey; | ||
|
||
@override | ||
State<ScanPage> createState() => _ScanPageState(); | ||
|
@@ -39,9 +42,31 @@ class _ScanPageState extends State<ScanPage> { | |
if (_model == null) { | ||
return const Center(child: CircularProgressIndicator()); | ||
} | ||
|
||
return ChangeNotifierProvider<ContinuousScanModel>( | ||
create: (BuildContext context) => _model!, | ||
child: ContinuousScanPage(), | ||
child: Navigator( | ||
key: widget.navigatorKey, | ||
onGenerateRoute: (RouteSettings routeSettings) { | ||
return MaterialPageRoute<dynamic>( | ||
builder: (BuildContext context) => _buildChild(), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
//This has to be build inside of the ChangeNotifierProvider to prevent the model to be disposed. | ||
Widget _buildChild() { | ||
//Don't build Scanner (+activate camera) when not on the Scan Tab | ||
if (widget.offstage) { | ||
_model?.stopQRView(); | ||
return const Center( | ||
child: Text( | ||
"This shouldn't be visible since only build when offstage, when you see this page send a email to [email protected]", | ||
)); | ||
} else { | ||
return const ContinuousScanPage(); | ||
} | ||
} | ||
} |
Oops, something went wrong.