Skip to content

Conversation

@Potatomonsta
Copy link
Contributor

@Potatomonsta Potatomonsta commented Jan 6, 2026

Description

This PR adds a new StacPopAction that allows popping the current route from the navigation stack. This action is useful for closing dialogs, bottom sheets, or navigating back to the previous screen with an optional result value.

Changes:

  • Added StacPopAction model class in stac_core with optional result parameter
  • Implemented StacPopActionParser to handle pop action execution using Navigator.pop()
  • Registered StacPopActionParser in StacService action parsers list
  • Added pop action type to ActionType enum
  • Exported StacPopAction in actions barrel file
  • Generated JSON serialization code for StacPopAction

Usage:
The action can be used in JSON configuration:

{
  "actionType": "pop",
  "result": {
    "key": "value"
  }
}

Or in Dart:

StacPopAction(result: {'key': 'value'})

Related Issues

Closes #

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

    • Pop navigation action added — routes can now navigate back and optionally return result data to the previous screen.
  • Framework Updates

    • Action handling extended to recognize and execute pop navigation actions across the parser and action systems, broadening supported navigation behaviors.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

📝 Walkthrough

Walkthrough

Adds a new "pop" action type, its StacPopAction model and JSON wiring, a StacPopActionParser that calls Navigator.pop with an optional result, and registers the parser in StacService; also exports were added to public action APIs.

Changes

Cohort / File(s) Summary
Core Action Definition
packages/stac_core/lib/foundation/specifications/action_type.dart, packages/stac_core/lib/actions/pop/stac_pop_action.dart, packages/stac_core/lib/actions/pop/stac_pop_action.g.dart
Added ActionType.pop enum value and StacPopAction with optional result; JSON (de)serialization generated. Review generated file for correct nullable typing of result.
Action Parser Implementation
packages/stac/lib/src/parsers/actions/stac_pop_action/stac_pop_action_parser.dart
New StacPopActionParser implementing StacActionParser; parses model and calls Navigator.pop(context, model.result) guarded by Navigator.canPop. Check null-safety and import/context expectations.
Public API Exports
packages/stac_core/lib/actions/actions.dart, packages/stac/lib/src/parsers/actions/actions.dart
Added exports for pop/stac_pop_action.dart and stac_pop_action_parser.dart. Verify public surface and package import paths.
Service Integration
packages/stac/lib/src/framework/stac_service.dart
Registered StacPopActionParser() in _actionParsers list. Confirm initialization order and no parser conflicts.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Client
    participant StacService
    participant StacPopActionParser
    participant Navigator as Flutter Navigator

    Client->>StacService: dispatch action JSON (type: "pop", result: {...})
    StacService->>StacPopActionParser: match actionType & getModel(json)
    StacPopActionParser->>StacPopActionParser: construct StacPopAction model
    StacPopActionParser->>Navigator: if canPop(context) pop(context, model.result)
    Navigator-->>Client: previous route receives result (optional)
    note right of StacPopActionParser `#DDEFEF`: New/changed interaction: pop with result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

feature

Suggested reviewers

  • divyanshub024

Poem

🐰 A tiny hop, a gentle pop,
I bounce back routes and never stop,
I carry crumbs of data light,
Return them swift into the night,
Hooray—another hop took flight!

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add StacPopAction for navigation stack management' accurately describes the main change in this PR, which introduces a new StacPopAction class for handling navigation stack operations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83ff138 and 38c094a.

📒 Files selected for processing (7)
  • packages/stac/lib/src/framework/stac_service.dart
  • packages/stac/lib/src/parsers/actions/actions.dart
  • packages/stac/lib/src/parsers/actions/stac_pop_action/stac_pop_action_parser.dart
  • packages/stac_core/lib/actions/actions.dart
  • packages/stac_core/lib/actions/pop/stac_pop_action.dart
  • packages/stac_core/lib/actions/pop/stac_pop_action.g.dart
  • packages/stac_core/lib/foundation/specifications/action_type.dart
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/stac_core/lib/actions/pop/stac_pop_action.dart
  • packages/stac/lib/src/parsers/actions/actions.dart
  • packages/stac_core/lib/actions/pop/stac_pop_action.g.dart
  • packages/stac/lib/src/parsers/actions/stac_pop_action/stac_pop_action_parser.dart
  • packages/stac_core/lib/foundation/specifications/action_type.dart
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-19T20:20:55.561Z
Learnt from: akhil-ge0rge
Repo: StacDev/stac PR: 399
File: packages/stac/lib/src/parsers/theme/stac_tool_tip_theme_data_parser.dart:9-26
Timestamp: 2025-12-19T20:20:55.561Z
Learning: In Flutter, TooltipThemeData.height is deprecated since v3.30.0-0.1.pre. Replace uses with TooltipThemeData.constraints: BoxConstraints(minHeight: value) to achieve the same minimum height. Apply this pattern to review any Dart/Flutter code that uses TooltipThemeData.height, not just this file.

Applied to files:

  • packages/stac_core/lib/actions/actions.dart
  • packages/stac/lib/src/framework/stac_service.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: pub_get_check
🔇 Additional comments (2)
packages/stac_core/lib/actions/actions.dart (1)

12-12: LGTM! Export correctly adds StacPopAction to the public API.

The export follows the established pattern and properly exposes the new pop action functionality.

packages/stac/lib/src/framework/stac_service.dart (1)

148-148: Parser implementation correctly follows framework conventions.

The StacPopActionParser is properly registered and implements all required abstract methods from StacActionParser with the same pattern as StacNavigateActionParser. The implementation includes appropriate safety checks (Navigator.canPop guard) and follows the const constructor convention.


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
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: 2

🤖 Fix all issues with AI Agents
In @packages/stac/lib/src/framework/stac_service.dart:
- Line 148: The StacPopActionParser's onCall currently calls
Navigator.pop(context, model.result) without guarding against an empty
navigation stack; update the onCall implementation in StacPopActionParser to
either check Navigator.canPop(context) before calling Navigator.pop or wrap
Navigator.pop(context, model.result) in a try-catch that logs the error (use
debugPrint or the existing logger) to avoid an exception when the stack is
empty; ensure you reference the model.result from StacPopAction and still return
null.

In
@packages/stac/lib/src/parsers/actions/stac_pop_action/stac_pop_action_parser.dart:
- Around line 17-21: The onCall implementation in StacPopAction parser calls
Navigator.pop(context, model.result) unconditionally which can throw if there is
no route to pop; update the onCall method to first check
Navigator.canPop(context) and only call Navigator.pop when canPop returns true
(otherwise do nothing or handle accordingly), keeping the method signature and
return behavior intact; reference the onCall method in the StacPopAction parser
and the Navigator.canPop/ Navigator.pop calls when making the change.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e209f56 and 83ff138.

📒 Files selected for processing (7)
  • packages/stac/lib/src/framework/stac_service.dart
  • packages/stac/lib/src/parsers/actions/actions.dart
  • packages/stac/lib/src/parsers/actions/stac_pop_action/stac_pop_action_parser.dart
  • packages/stac_core/lib/actions/actions.dart
  • packages/stac_core/lib/actions/pop/stac_pop_action.dart
  • packages/stac_core/lib/actions/pop/stac_pop_action.g.dart
  • packages/stac_core/lib/foundation/specifications/action_type.dart
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-19T20:20:55.561Z
Learnt from: akhil-ge0rge
Repo: StacDev/stac PR: 399
File: packages/stac/lib/src/parsers/theme/stac_tool_tip_theme_data_parser.dart:9-26
Timestamp: 2025-12-19T20:20:55.561Z
Learning: In Flutter, TooltipThemeData.height is deprecated since v3.30.0-0.1.pre. Replace uses with TooltipThemeData.constraints: BoxConstraints(minHeight: value) to achieve the same minimum height. Apply this pattern to review any Dart/Flutter code that uses TooltipThemeData.height, not just this file.

Applied to files:

  • packages/stac_core/lib/actions/actions.dart
  • packages/stac_core/lib/foundation/specifications/action_type.dart
  • packages/stac/lib/src/parsers/actions/actions.dart
  • packages/stac_core/lib/actions/pop/stac_pop_action.g.dart
  • packages/stac/lib/src/framework/stac_service.dart
  • packages/stac_core/lib/actions/pop/stac_pop_action.dart
  • packages/stac/lib/src/parsers/actions/stac_pop_action/stac_pop_action_parser.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: analyze
  • GitHub Check: pub_get_check
🔇 Additional comments (6)
packages/stac/lib/src/parsers/actions/actions.dart (1)

7-7: LGTM! Clean export addition.

The export is correctly positioned alphabetically and follows the established pattern for action parser exports.

packages/stac_core/lib/foundation/specifications/action_type.dart (1)

38-40: LGTM! Well-documented enum addition.

The pop action type is clearly documented and follows the established pattern for enum values in this file.

packages/stac_core/lib/actions/actions.dart (1)

12-12: LGTM! Export addition looks good.

The StacPopAction export is correctly added to the actions barrel file.

packages/stac_core/lib/actions/pop/stac_pop_action.g.dart (1)

1-16: LGTM! Standard generated serialization code.

The JSON serialization logic is correctly generated by json_serializable. The code appropriately:

  • Deserializes the optional result field as Map<String, dynamic>?
  • Serializes both result and actionType for consistency
packages/stac_core/lib/actions/pop/stac_pop_action.dart (1)

1-49: LGTM! Well-documented action model with appropriate design.

The implementation is clean and follows the established pattern for STAC actions:

  • Proper JSON serialization setup with generated code
  • Comprehensive documentation with both Dart and JSON examples
  • Flexible result field type (Map<String, dynamic>?) is appropriate for a generic action framework
  • Const constructor enables compile-time optimization

The action model correctly integrates with the framework's type system via actionType override.

packages/stac/lib/src/parsers/actions/stac_pop_action/stac_pop_action_parser.dart (1)

10-11: ActionType.pop enum value confirmed.

ActionType.pop exists in the ActionType enum at line 40 of packages/stac_core/lib/foundation/specifications/action_type.dart with proper documentation.

const StacSetValueActionParser(),
const StacMultiActionParser(),
const StacDelayActionParser(),
const StacPopActionParser(),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find StacPopActionParser implementation
fd -t f 'stac_pop_action_parser.dart' --exec cat {}

Repository: StacDev/stac

Length of output: 621


Consider adding error handling for empty navigation stack.

The parser correctly passes the result value from the model to Navigator.pop(). However, the implementation lacks error handling for when the navigation stack is empty. Navigator.pop() will throw an exception in this case, potentially crashing the app. Add a try-catch block or validate the navigation stack before popping:

@override
FutureOr onCall(BuildContext context, StacPopAction model) {
  try {
    Navigator.pop(context, model.result);
  } catch (e) {
    debugPrint('Failed to pop navigation: $e');
  }
  return null;
}
🤖 Prompt for AI Agents
In @packages/stac/lib/src/framework/stac_service.dart at line 148, The
StacPopActionParser's onCall currently calls Navigator.pop(context,
model.result) without guarding against an empty navigation stack; update the
onCall implementation in StacPopActionParser to either check
Navigator.canPop(context) before calling Navigator.pop or wrap
Navigator.pop(context, model.result) in a try-catch that logs the error (use
debugPrint or the existing logger) to avoid an exception when the stack is
empty; ensure you reference the model.result from StacPopAction and still return
null.

Implement a new action type that allows popping the current route from
the navigation stack. This action is useful for closing dialogs, bottom
sheets, or navigating back to the previous screen with an optional
result value.

Changes:
- Add StacPopAction model class in stac_core with optional result parameter
- Add StacPopActionParser to handle pop action execution
- Register StacPopActionParser in StacService action parsers list
- Export StacPopAction in actions.dart barrel file
- Add 'pop' action type to ActionType enum
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.

3 participants