We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, Thanks for the amazing work. I encountered a problem, where hot reload not working for the screens inside the navigator. Here is my code
class App extends StatefulWidget { @override _AppState createState() => _AppState(); } class _AppState extends State<App> { final Map<TabItem, Map<String, Object>> _navItems = { TabItem.CALCULATOR: { 'icon': FlutterIcons.calc, 'title': 'Calculator', 'pageTitle': 'Stock Calculator', 'key': GlobalKey<NavigatorState>() }, TabItem.ACCOUNTS: { 'icon': Icons.insert_chart, 'title': 'Accounts', 'pageTitle': 'Accounts', 'key': GlobalKey<NavigatorState>() }, TabItem.SETTINGS: { 'icon': Icons.settings, 'title': 'Settings', 'pageTitle': 'Settings', 'key': GlobalKey<NavigatorState>() }, }; TabItem _currentTab = TabItem.CALCULATOR; Widget _renderPage() { Map<String, Object> item = _navItems[_currentTab]; var key = item['key'] as GlobalKey<NavigatorState>; var pageTitle = item['pageTitle'] as String; switch (_currentTab) { case TabItem.CALCULATOR: return HomePage( key: key, title: pageTitle, ); break; case TabItem.ACCOUNTS: return AccountsPage( key: key, title: pageTitle, ); break; case TabItem.SETTINGS: return SettingsPageNavigator( navigatorKey: key, tabItem: TabItem.SETTINGS, ); break; default: return HomePage( key: key, title: pageTitle, ); } } @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { bool flag = true; try { if (TabItem.SETTINGS == _currentTab) { final isFirstRouteInCurrentTab = await (_navItems[_currentTab] ['key'] as GlobalKey<NavigatorState>) .currentState .maybePop(); if (isFirstRouteInCurrentTab) { _onTabSelect(TabItem.SETTINGS); flag = false; } } } catch (e) {} return flag; }, child: Scaffold( backgroundColor: Colors.red, body: _renderPage(), bottomNavigationBar: BottomNavigationBar( backgroundColor: Theme.of(context).primaryColor, unselectedItemColor: Colors.white54, selectedItemColor: Colors.white, onTap: (index) => _onTabSelect(TabItem.values[index]), currentIndex: _currentTab.index, elevation: 5, type: BottomNavigationBarType.fixed, items: [ _buildNavItem(tabItem: TabItem.CALCULATOR), _buildNavItem(tabItem: TabItem.ACCOUNTS), _buildNavItem(tabItem: TabItem.SETTINGS), ], ), ), ); } _onTabSelect(TabItem tab) { setState(() { _currentTab = tab; }); } BottomNavigationBarItem _buildNavItem({TabItem tabItem}) { return BottomNavigationBarItem( icon: Icon(_navItems[tabItem]['icon']), title: Text(_navItems[tabItem]['title'])); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi,
Thanks for the amazing work. I encountered a problem, where hot reload not working for the screens inside the navigator. Here is my code
The text was updated successfully, but these errors were encountered: