Skip to content

Commit 1023c79

Browse files
committed
refactor: Improve top navigation active state and dropdown styling
This commit updates the `TopNavigation` widget to correctly highlight parent navigation items when a sub-item is active and refines the dropdown menu layout. ### Key Changes: * **Active State Logic (`top_navigation.dart`):** * Updated the `isActive` property for `LightButton` to remain true if either the item itself or any of its children are currently selected in the `navigationShell`. This ensures parent categories stay highlighted when a sub-page is active. * **Dropdown UI Refinement (`top_navigation.dart`):** * Removed the `ModalContainer` wrapper from the `Popover` builder, simplifying the widget hierarchy. * Applied `.intrinsicWidth()` to the `DropdownMenu` to ensure it sizes correctly based on its content. * Removed hardcoded vertical padding from the dropdown container in favor of the default `DropdownMenu` styling.
1 parent 8bd3cc8 commit 1023c79

1 file changed

Lines changed: 39 additions & 39 deletions

File tree

lib/screens/widgets/layouts/widgets/top_navigation.dart

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ class TopNavigation extends StatelessWidget {
5252
(item) =>
5353
(LightButton(
5454
onPressed: () => _onPressed(context, item),
55-
isActive: item.index == navigationShell.currentIndex,
55+
isActive:
56+
item.index == navigationShell.currentIndex ||
57+
item.children.any(
58+
(subItem) =>
59+
subItem.index == navigationShell.currentIndex,
60+
),
5661
isIcon: false,
5762
trailing: item.children.isEmpty
5863
? null
@@ -82,48 +87,43 @@ class TopNavigation extends StatelessWidget {
8287
enablePress: true,
8388
offset: const Offset(0, -4),
8489
builder: (context) {
85-
return ModalContainer(
86-
padding: const EdgeInsets.symmetric(vertical: 8),
87-
child: DropdownMenu(
88-
children: item.children
89-
.map(
90-
(subItem) => MenuButton(
91-
onPressed: (context) {
92-
_onPressed(context, subItem);
93-
},
94-
enabled: subItem.index !=
95-
navigationShell.currentIndex,
96-
leading:
97-
subItem.index ==
98-
navigationShell.currentIndex
99-
? IconTheme(
100-
data: IconThemeData(
101-
color: Colors.gray[400],
102-
size: 16,
103-
),
104-
child: subItem.icon!,
105-
)
106-
: subItem.icon,
107-
trailing:
90+
return DropdownMenu(
91+
children: item.children
92+
.map(
93+
(subItem) => MenuButton(
94+
onPressed: (context) {
95+
_onPressed(context, subItem);
96+
},
97+
enabled:
98+
subItem.index != navigationShell.currentIndex,
99+
leading:
100+
subItem.index == navigationShell.currentIndex
101+
? IconTheme(
102+
data: IconThemeData(
103+
color: Colors.gray[400],
104+
size: 16,
105+
),
106+
child: subItem.icon!,
107+
)
108+
: subItem.icon,
109+
trailing:
110+
subItem.index == navigationShell.currentIndex
111+
? Icon(
112+
LucideIcons.mapPin,
113+
color: Colors.gray[400],
114+
)
115+
: null,
116+
child: Text(
117+
subItem.title,
118+
style:
108119
subItem.index ==
109120
navigationShell.currentIndex
110-
? Icon(
111-
LucideIcons.mapPin,
112-
color: Colors.gray[400],
113-
)
121+
? TextStyle(color: Colors.gray[400])
114122
: null,
115-
child: Text(
116-
subItem.title,
117-
style:
118-
subItem.index ==
119-
navigationShell.currentIndex
120-
? TextStyle(color: Colors.gray[400])
121-
: null,
122-
),
123123
),
124-
)
125-
.toList(),
126-
),
124+
),
125+
)
126+
.toList(),
127127
).intrinsicWidth();
128128
},
129129
)),

0 commit comments

Comments
 (0)