Skip to content

Commit 23df358

Browse files
committed
fix: defer BottomNavigationScope access to build time in navigation parsers
- Wrap StacBottomNavigationBar in _BottomNavigationBarWidget to defer controller access - Wrap StacBottomNavigationView in _BottomNavigationViewWidget to defer controller access - Move BottomNavigationScope.of(context) calls from parse() to build() methods - Fix timing issue where InheritedWidget was accessed before being created The issue was that both navigation parsers were calling BottomNavigationScope.of(context) during the parsing phase, before the BottomNavigationScope was actually created in the widget tree by StacDefaultBottomNavigationController. This caused the controller to be null and prevented proper communication between the navigation bar and view. By wrapping the widgets and deferring the BottomNavigationScope access to build time, the InheritedWidget is guaranteed to be available when needed, ensuring proper bottom navigation functionality.
1 parent d98aacc commit 23df358

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/stac/lib/src/parsers/widgets/stac_bottom_navigation_bar/stac_bottom_navigation_bar_parser.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ class StacBottomNavigationBarParser
2121

2222
@override
2323
Widget parse(BuildContext context, StacBottomNavigationBar model) {
24+
return _BottomNavigationBarWidget(model: model);
25+
}
26+
}
27+
28+
class _BottomNavigationBarWidget extends StatelessWidget {
29+
const _BottomNavigationBarWidget({required this.model});
30+
31+
final StacBottomNavigationBar model;
32+
33+
@override
34+
Widget build(BuildContext context) {
2435
final controller = BottomNavigationScope.of(context)?.controller;
2536

2637
return BottomNavigationBar(

packages/stac/lib/src/parsers/widgets/stac_bottom_navigation_view/stac_bottom_navigation_view_parser.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ class StacBottomNavigationViewParser
1717

1818
@override
1919
Widget parse(BuildContext context, StacBottomNavigationView model) {
20+
return _BottomNavigationViewWidget(model: model);
21+
}
22+
}
23+
24+
class _BottomNavigationViewWidget extends StatelessWidget {
25+
const _BottomNavigationViewWidget({required this.model});
26+
27+
final StacBottomNavigationView model;
28+
29+
@override
30+
Widget build(BuildContext context) {
2031
final controller = BottomNavigationScope.of(context)?.controller;
2132
if (model.children.isEmpty) return const SizedBox();
2233
final index = controller?.index ?? 0;

0 commit comments

Comments
 (0)