-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add navigate to view group action #860
Changes from 3 commits
9b70228
a1485e2
56c9d9d
ea84cd3
d937f8c
bb78938
28065b6
2f6191e
2dcbeea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,19 @@ import 'package:ensemble/framework/extensions.dart'; | |
import '../widget/custom_view.dart'; | ||
import 'bottom_nav_page_group.dart'; | ||
|
||
class PageGroupNotifier extends ChangeNotifier { | ||
int _viewIndex = 0; | ||
|
||
int get viewIndex => _viewIndex; | ||
|
||
void updatePage(int index) { | ||
_viewIndex = index; | ||
notifyListeners(); | ||
} | ||
} | ||
|
||
final pageNotifier = PageGroupNotifier(); | ||
|
||
/// a collection of pages grouped under a navigation menu | ||
class PageGroup extends StatefulWidget { | ||
const PageGroup( | ||
|
@@ -113,6 +126,14 @@ class PageGroupState extends State<PageGroup> with MediaQueryCapability { | |
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListenableBuilder( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will recreate the entire ViewGroup from scratch - we don't want that. We simply want to switch the Tab to another screen. Please make sure we don't rebuild items unnecessary. Optimization is important for our framework as the app could be gigantic. |
||
listenable: pageNotifier, | ||
builder: (context, _) => buildPageGroupChild(), | ||
); | ||
} | ||
|
||
Widget buildPageGroupChild() { | ||
final selectedPage = pageNotifier.viewIndex; | ||
// skip rendering the menu if only 1 menu item, just the content itself | ||
if (widget.menu.menuItems.length == 1) { | ||
return pageWidgets[0]; | ||
|
@@ -125,16 +146,19 @@ class PageGroupState extends State<PageGroup> with MediaQueryCapability { | |
Drawer? drawer = _buildDrawer(context, widget.menu); | ||
bool atStart = (widget.menu as DrawerMenu).atStart; | ||
return PageGroupWidget( | ||
key: UniqueKey(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't do this. Almost never use UniqueKey(). |
||
scopeManager: _scopeManager, | ||
navigationDrawer: atStart ? drawer : null, | ||
navigationEndDrawer: !atStart ? drawer : null, | ||
child: pageWidgets[selectedPage]); | ||
} else if (widget.menu is SidebarMenu) { | ||
return PageGroupWidget( | ||
key: UniqueKey(), | ||
scopeManager: _scopeManager, | ||
child: buildSidebarNavigation(context, widget.menu as SidebarMenu)); | ||
} else if (widget.menu is BottomNavBarMenu) { | ||
return BottomNavPageGroup( | ||
key: UniqueKey(), | ||
scopeManager: _scopeManager, | ||
selectedPage: selectedPage, | ||
menu: widget.menu, | ||
|
@@ -149,8 +173,9 @@ class PageGroupState extends State<PageGroup> with MediaQueryCapability { | |
Widget buildSidebarNavigation(BuildContext context, SidebarMenu menu) { | ||
Widget sidebar = _buildSidebar(context, menu); | ||
Widget? separator = _buildSidebarSeparator(menu); | ||
Widget content = Expanded(child: pageWidgets[selectedPage]); | ||
|
||
Widget content = Expanded( | ||
child: IndexedStack(index: selectedPage, children: pageWidgets), | ||
); | ||
// figuring out the direction to lay things out | ||
bool rtlLocale = Directionality.of(context) == TextDirection.rtl; | ||
// standard layout is the sidebar menu then content | ||
|
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.
add " (applicable only when inside a ViewGroup)"