feat: Add support for the NavigationBar widget#476
Conversation
- Introduced the `navigation_bar` widget to the documentation and examples. - Added `StacNavigationBarParser` and `StacNavigationViewParser` to support the new navigation structure. - Updated existing parsers to replace deprecated bottom navigation components with the new navigation system. - Enhanced JSON examples for the navigation bar to improve usability and clarity.
- Removed the MinimumOSVersion key from AppFrameworkInfo.plist. - Added a _clampIndex method to ensure valid index values in the DefaultNavigationController. - Enhanced the didUpdateWidget method to handle index changes more effectively. - Updated NavigationScope to include the current index and improved its update logic. - Refactored the NavigationBar widget to utilize the new NavigationScope methods for better index handling.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds Material 3 navigation models (NavigationBar, NavigationView, NavigationDestination), a StacDefaultNavigationController runtime/parser (NavigationScope/NavigationController), corresponding parsers, deprecates bottom-navigation equivalents, updates barrel exports, and adds docs and gallery examples. ChangesMaterial 3 Navigation System
Sequence DiagramsequenceDiagram
participant JSON as Gallery/Docs JSON
participant StacService as StacService
participant Parser as StacDefaultNavigationControllerParser
participant StateWidget as _DefaultNavigationControllerWidget
participant NavController as NavigationController
participant NavScope as NavigationScope
participant NavBar as _NavigationBarWidget
participant NavView as _NavigationViewWidget
JSON->>StacService: register/resolve parser entries
JSON->>Parser: parse(defaultNavigationController config)
Parser->>StateWidget: instantiate with length, initialIndex
StateWidget->>NavController: create NavigationController(length, initialIndex)
StateWidget->>NavScope: provide controller+index to descendants
NavScope->>NavBar: provide controller/index
NavScope->>NavView: provide controller/index
NavBar->>NavController: onDestinationSelected(index)
NavController->>NavScope: notify index change
NavScope->>NavView: notify and cause selected child to render
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/stac_core/lib/widgets/navigation_bar/stac_navigation_bar.dart (1)
53-53: ⚡ Quick winRemove
explicitToJson: truefrom the annotation.The
stac_corepackage configuresexplicitToJson: trueglobally viabuild.yaml. Individual@JsonSerializableannotations should rely on this global setting unless there's a documented justification for different behavior.♻️ Proposed fix
-@JsonSerializable(explicitToJson: true) +@JsonSerializable() class StacNavigationBar extends StacWidget {Based on learnings: In the stac_core package (packages/stac_core), explicitToJson: true is configured globally via build.yaml for json_serializable. Do not specify explicitToJson: true on individual JsonSerializable annotations in this package; rely on the global setting. If a file in this package needs a different behavior, document and justify it.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/stac_core/lib/widgets/navigation_bar/stac_navigation_bar.dart` at line 53, Remove the explicitToJson: true override from the `@JsonSerializable` annotation on the StacNavigationBar widget (the annotation currently above the class in stac_navigation_bar.dart); rely on the package-wide setting in build.yaml instead and leave the annotation as `@JsonSerializable`() or just `@JsonSerializable` with no explicitToJson parameter so it inherits the global configuration.packages/stac_core/lib/foundation/navigation/stac_navigation_destination/stac_navigation_destination.dart (1)
31-31: ⚡ Quick winRemove
explicitToJson: truefrom the annotation.The
stac_corepackage configuresexplicitToJson: trueglobally viabuild.yaml. Individual@JsonSerializableannotations should rely on this global setting unless there's a documented justification for different behavior.♻️ Proposed fix
-@JsonSerializable(explicitToJson: true) +@JsonSerializable() class StacNavigationDestination extends StacElement {Based on learnings: In the stac_core package (packages/stac_core), explicitToJson: true is configured globally via build.yaml for json_serializable. Do not specify explicitToJson: true on individual JsonSerializable annotations in this package; rely on the global setting. If a file in this package needs a different behavior, document and justify it.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/stac_core/lib/foundation/navigation/stac_navigation_destination/stac_navigation_destination.dart` at line 31, Remove the explicitToJson: true parameter from the `@JsonSerializable` annotation in this file so the annotation relies on the package-level configuration in build.yaml; locate the `@JsonSerializable`(...) usage near the top of stac_navigation_destination.dart and edit the annotation to omit explicitToJson while leaving other annotation parameters intact (i.e., change `@JsonSerializable`(explicitToJson: true) to simply `@JsonSerializable`()).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/stac/lib/src/parsers/widgets/stac_default_navigation_controller/stac_default_navigation_controller_parser.dart`:
- Around line 162-163: NavigationController currently stores initialIndex
directly (constructor NavigationController) and relies on assert in the
_changeIndex setter for bounds, which is disabled in release builds; update the
constructor to validate/clamp initialIndex at runtime (e.g., clamp to
0..length-1 or throw a RangeError) and replace assert-based checks in the setter
_changeIndex with explicit runtime validation (throw RangeError) so _index can
never be out-of-range; reference initState and didUpdateWidget callers to ensure
they can pass values safely into NavigationController after this change.
---
Nitpick comments:
In
`@packages/stac_core/lib/foundation/navigation/stac_navigation_destination/stac_navigation_destination.dart`:
- Line 31: Remove the explicitToJson: true parameter from the `@JsonSerializable`
annotation in this file so the annotation relies on the package-level
configuration in build.yaml; locate the `@JsonSerializable`(...) usage near the
top of stac_navigation_destination.dart and edit the annotation to omit
explicitToJson while leaving other annotation parameters intact (i.e., change
`@JsonSerializable`(explicitToJson: true) to simply `@JsonSerializable`()).
In `@packages/stac_core/lib/widgets/navigation_bar/stac_navigation_bar.dart`:
- Line 53: Remove the explicitToJson: true override from the `@JsonSerializable`
annotation on the StacNavigationBar widget (the annotation currently above the
class in stac_navigation_bar.dart); rely on the package-wide setting in
build.yaml instead and leave the annotation as `@JsonSerializable`() or just
`@JsonSerializable` with no explicitToJson parameter so it inherits the global
configuration.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e5de564c-1463-44e8-becc-25adbb6dec66
📒 Files selected for processing (26)
docs/docs.jsondocs/widgets/navigation_bar.mdxexamples/stac_gallery/assets/json/home_screen.jsonexamples/stac_gallery/assets/json/navigation_bar_example.jsonexamples/stac_gallery/ios/Flutter/AppFrameworkInfo.plistpackages/stac/lib/src/framework/stac_service.dartpackages/stac/lib/src/parsers/widgets/stac_bottom_navigation_bar/stac_bottom_navigation_bar_parser.dartpackages/stac/lib/src/parsers/widgets/stac_bottom_navigation_view/stac_bottom_navigation_view_parser.dartpackages/stac/lib/src/parsers/widgets/stac_default_bottom_navigation_controller/stac_default_bottom_navigation_controller_parser.dartpackages/stac/lib/src/parsers/widgets/stac_default_navigation_controller/stac_default_navigation_controller_parser.dartpackages/stac/lib/src/parsers/widgets/stac_navigation_bar/stac_navigation_bar_parser.dartpackages/stac/lib/src/parsers/widgets/stac_navigation_view/stac_navigation_view_parser.dartpackages/stac/lib/src/parsers/widgets/widgets.dartpackages/stac_core/lib/foundation/foundation.dartpackages/stac_core/lib/foundation/navigation/stac_navigation_destination/stac_navigation_destination.dartpackages/stac_core/lib/foundation/navigation/stac_navigation_destination/stac_navigation_destination.g.dartpackages/stac_core/lib/foundation/specifications/widget_type.dartpackages/stac_core/lib/widgets/bottom_navigation_view/stac_bottom_navigation_view.dartpackages/stac_core/lib/widgets/default_bottom_navigation_controller/stac_default_bottom_navigation_controller.dartpackages/stac_core/lib/widgets/default_navigation_controller/stac_default_navigation_controller.dartpackages/stac_core/lib/widgets/default_navigation_controller/stac_default_navigation_controller.g.dartpackages/stac_core/lib/widgets/navigation_bar/stac_navigation_bar.dartpackages/stac_core/lib/widgets/navigation_bar/stac_navigation_bar.g.dartpackages/stac_core/lib/widgets/navigation_view/stac_navigation_view.dartpackages/stac_core/lib/widgets/navigation_view/stac_navigation_view.g.dartpackages/stac_core/lib/widgets/widgets.dart
💤 Files with no reviewable changes (1)
- examples/stac_gallery/ios/Flutter/AppFrameworkInfo.plist
- Introduced a _clampIndex method to ensure valid index values during initialization and updates. - Updated the NavigationController constructor to use clamped initial index values. - Improved index validation logic to prevent out-of-bounds errors when changing the index.
Description
Add support for the NavigationBar widget
Type of Change
Summary by CodeRabbit
New Features
Documentation
Deprecations