Skip to content

feat: Add support for the NavigationBar widget#476

Open
divyanshub024 wants to merge 4 commits into
devfrom
dv/navigation-bar
Open

feat: Add support for the NavigationBar widget#476
divyanshub024 wants to merge 4 commits into
devfrom
dv/navigation-bar

Conversation

@divyanshub024
Copy link
Copy Markdown
Member

@divyanshub024 divyanshub024 commented May 12, 2026

Description

Add support for the NavigationBar widget

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Code refactor
  • Build configuration change
  • Documentation
  • Chore

Summary by CodeRabbit

  • New Features

    • Added NavigationBar, NavigationView, DefaultNavigationController, and NavigationDestination for Material 3 navigation.
  • Documentation

    • Added comprehensive NavigationBar docs with examples and a playground preview.
    • Added gallery example and a dedicated navigation-bar example screen.
  • Deprecations

    • Marked legacy bottom-navigation components as deprecated; migrate to the new navigation APIs.

Review Change Stack

- 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.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 38d20200-3b64-4357-8c8f-9457dd8190c6

📥 Commits

Reviewing files that changed from the base of the PR and between 882ab1b and 594d7db.

📒 Files selected for processing (1)
  • packages/stac/lib/src/parsers/widgets/stac_default_navigation_controller/stac_default_navigation_controller_parser.dart
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/stac/lib/src/parsers/widgets/stac_default_navigation_controller/stac_default_navigation_controller_parser.dart

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Material 3 Navigation System

Layer / File(s) Summary
Navigation destination and controller models
packages/stac_core/lib/foundation/navigation/stac_navigation_destination/*, packages/stac_core/lib/widgets/navigation_bar/*, packages/stac_core/lib/widgets/navigation_view/*, packages/stac_core/lib/widgets/default_navigation_controller/*, packages/stac_core/lib/foundation/specifications/widget_type.dart
Adds StacNavigationDestination, StacNavigationBar, StacNavigationView, and StacDefaultNavigationController models with JSON (de)serialization and updates WidgetType doc comments.
Navigation scope and controller parser
packages/stac/lib/src/parsers/widgets/stac_default_navigation_controller/*
Implements StacDefaultNavigationControllerParser producing a stateful widget that creates/owns NavigationController, exposes NavigationScope, clamps indices, manages listeners, and recreates controller on relevant updates.
NavigationBar parser and widget
packages/stac/lib/src/parsers/widgets/stac_navigation_bar/*, packages/stac_core/lib/widgets/navigation_bar/*
Adds StacNavigationBarParser and internal widget that maps StacNavigationDestination entries to Flutter NavigationBar, computes selectedIndex using NavigationScope controller when available, and wires selection events to the controller.
NavigationView parser and widget
packages/stac/lib/src/parsers/widgets/stac_navigation_view/*, packages/stac_core/lib/widgets/navigation_view/*
Adds StacNavigationViewParser which renders the selected child from model.children using the controller index from NavigationScope with bounds checking and empty fallbacks.
Bottom navigation deprecation and migration
packages/stac_core/lib/widgets/bottom_navigation_view/*, packages/stac_core/lib/widgets/default_bottom_navigation_controller/*, packages/stac/lib/src/parsers/widgets/stac_bottom_navigation_*/*
Marks bottom-navigation widgets/controllers deprecated, adds deprecated type aliases, and updates bottom-navigation parsers to delegate to the new navigation controller/scope.
Framework and barrel export integration
packages/stac/lib/src/framework/stac_service.dart, packages/stac/lib/src/parsers/widgets/widgets.dart, packages/stac_core/lib/foundation/foundation.dart, packages/stac_core/lib/widgets/widgets.dart
Registers new parsers in StacService, exports navigation parsers/models in barrel files, and reorders some export blocks.
Documentation and gallery examples
docs/docs.json, docs/widgets/navigation_bar.mdx, examples/stac_gallery/assets/json/*, examples/stac_gallery/ios/Flutter/AppFrameworkInfo.plist
Adds NavigationBar documentation with preview JSON/embed helpers and iframe postMessage retry, adds gallery entry and JSON example, and removes MinimumOSVersion from iOS AppFrameworkInfo.plist.

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • StacDev/stac#361: Overlapping navigation system refactor—migration from bottom navigation controller to default navigation controller and NavigationScope.
  • StacDev/stac#424: Adds parsers and registry updates similar to this change (parser registration in StacService).
  • StacDev/stac#379: Related changes touching navigation destination label-behavior and enum mapping used by navigation widgets.

Suggested labels

feature

Suggested reviewers

  • Potatomonsta

Poem

🐰 A new navigator hops into view,
With Material 3 scope to pursue,
Old bottom-nav friends take a graceful bow,
Controllers and scopes bind the widgets now,
Gallery and docs cheer — hop, review anew!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature being added: support for the NavigationBar widget, which is a Material 3 navigation component introduced across the STAC framework.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dv/navigation-bar

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/stac_core/lib/widgets/navigation_bar/stac_navigation_bar.dart (1)

53-53: ⚡ Quick win

Remove explicitToJson: true from the annotation.

The stac_core package configures explicitToJson: true globally via build.yaml. Individual @JsonSerializable annotations 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 win

Remove explicitToJson: true from the annotation.

The stac_core package configures explicitToJson: true globally via build.yaml. Individual @JsonSerializable annotations 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2907c6a and 882ab1b.

📒 Files selected for processing (26)
  • docs/docs.json
  • docs/widgets/navigation_bar.mdx
  • examples/stac_gallery/assets/json/home_screen.json
  • examples/stac_gallery/assets/json/navigation_bar_example.json
  • examples/stac_gallery/ios/Flutter/AppFrameworkInfo.plist
  • packages/stac/lib/src/framework/stac_service.dart
  • packages/stac/lib/src/parsers/widgets/stac_bottom_navigation_bar/stac_bottom_navigation_bar_parser.dart
  • packages/stac/lib/src/parsers/widgets/stac_bottom_navigation_view/stac_bottom_navigation_view_parser.dart
  • packages/stac/lib/src/parsers/widgets/stac_default_bottom_navigation_controller/stac_default_bottom_navigation_controller_parser.dart
  • packages/stac/lib/src/parsers/widgets/stac_default_navigation_controller/stac_default_navigation_controller_parser.dart
  • packages/stac/lib/src/parsers/widgets/stac_navigation_bar/stac_navigation_bar_parser.dart
  • packages/stac/lib/src/parsers/widgets/stac_navigation_view/stac_navigation_view_parser.dart
  • packages/stac/lib/src/parsers/widgets/widgets.dart
  • packages/stac_core/lib/foundation/foundation.dart
  • packages/stac_core/lib/foundation/navigation/stac_navigation_destination/stac_navigation_destination.dart
  • packages/stac_core/lib/foundation/navigation/stac_navigation_destination/stac_navigation_destination.g.dart
  • packages/stac_core/lib/foundation/specifications/widget_type.dart
  • packages/stac_core/lib/widgets/bottom_navigation_view/stac_bottom_navigation_view.dart
  • packages/stac_core/lib/widgets/default_bottom_navigation_controller/stac_default_bottom_navigation_controller.dart
  • packages/stac_core/lib/widgets/default_navigation_controller/stac_default_navigation_controller.dart
  • packages/stac_core/lib/widgets/default_navigation_controller/stac_default_navigation_controller.g.dart
  • packages/stac_core/lib/widgets/navigation_bar/stac_navigation_bar.dart
  • packages/stac_core/lib/widgets/navigation_bar/stac_navigation_bar.g.dart
  • packages/stac_core/lib/widgets/navigation_view/stac_navigation_view.dart
  • packages/stac_core/lib/widgets/navigation_view/stac_navigation_view.g.dart
  • packages/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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant