Skip to content

Conversation

@Sharath-a26
Copy link

@Sharath-a26 Sharath-a26 commented Oct 28, 2025

Network Widget

Description

  • Added loadingWidget and errorWidget fields to StacNetworkWidget model
  • Updated JSON serialization to support the new fields
  • Updated parser to pass these widgets to the network request

Related Issues

Closes #243

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 "Stac Network Widget" example to the gallery demonstrating network request handling with configurable UI states.
    • Enhanced network widget to support custom loading and error UI states for better user feedback during network operations.
  • Tests

    • Added comprehensive tests for network widget serialization and deserialization with optional state widgets.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Sharath S R seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Walkthrough

The pull request adds support for custom loading and error widgets to the Stac network widget. Two new optional fields (loadingWidget and errorWidget) are introduced to StacNetworkWidget, with corresponding serialization support, parser updates, test coverage, and example gallery assets demonstrating the feature.

Changes

Cohort / File(s) Summary
Gallery Example Assets
examples/stac_gallery/assets/json/home_screen.json, examples/stac_gallery/assets/json/network_widget_example.json
Added navigation entry for Stac Network Widget example in home screen; created new example JSON demonstrating the network widget with custom loading and error UI states.
Core Widget Definition
packages/stac_core/lib/widgets/network_widget/stac_network_widget.dart, packages/stac_core/lib/widgets/network_widget/stac_network_widget.g.dart
Extended StacNetworkWidget with two new optional fields (loadingWidget, errorWidget) in constructor and public API; updated serialization logic (fromJson/toJson) to handle the new fields.
Widget Parser
packages/stac/lib/src/parsers/widgets/stac_network_widget/stac_network_widget_parser.dart
Updated parser to pass loadingWidget and errorWidget builders to Stac.fromNetwork, converting them via StacService.fromStacWidget and falling back to SizedBox when null.
Widget Tests
packages/stac_core/test/widgets/network_widget/stac_network_widget_test.dart
Added comprehensive test suite covering JSON deserialization and serialization with and without optional loading and error widgets.

Sequence Diagram

sequenceDiagram
    participant Parser as StacNetworkWidget Parser
    participant Service as StacService
    participant Network as Stac.fromNetwork
    
    Parser->>Service: Extract loadingWidget (if present)
    Service->>Service: Convert via fromStacWidget
    
    Parser->>Service: Extract errorWidget (if present)
    Service->>Service: Convert via fromStacWidget
    
    Parser->>Network: Pass request + loadingWidget builder + errorWidget builder
    
    alt Network Request
        Network->>Network: Request initiated
        Network->>Network: Show loadingWidget if provided
        Network->>Network: Success or Error
    end
    
    alt Success State
        Network->>Network: Display loaded content
    else Error State
        Network->>Network: Show errorWidget if provided
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • The changes follow a consistent pattern: adding two new optional fields across the data class, parser, and serialization layer
  • Most modifications are straightforward additions with minimal logic density
  • Test coverage is present and validates the new functionality
  • Key areas to verify during review:
    • Null-safety handling in parser builders (fallback to SizedBox)
    • Serialization correctness in generated code
    • Test coverage completeness for both with/without optional widgets scenarios

Suggested reviewers

  • Potatomonsta
  • divyanshub024

Poem

🐰 A widget hops through the network night,
With loading spinners shining bright,
When errors peek, we don't despair,
Custom widgets show we care!
From cloud to screen, the data flows free,

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat(networkWidget): added loader and error widget support to networkwidget" accurately describes the primary change in the changeset. The title is concise, specific, and directly conveys that loader and error widget support has been added to the networkWidget feature. The title follows conventional commit format and clearly indicates this is a new feature. A teammate reviewing the commit history would understand that this PR adds custom widget support for handling loading and error states in network requests.
Linked Issues Check ✅ Passed The pull request successfully addresses the requirements from issue #243. The implementation adds loadingWidget and errorWidget fields to the StacNetworkWidget model [#243], updates JSON serialization to support these new optional fields, and modifies the parser to pass these widgets to the network request handler [#243]. The PR also includes test coverage for the serialization and deserialization of these new fields, and provides a practical example in the gallery demonstrating the feature. All coding requirements from the linked issue have been met and the feature enables displaying custom loader and error widgets during network operations as requested.
Out of Scope Changes Check ✅ Passed All changes in the pull request are directly related to the feature objective of adding loader and error widget support to the networkWidget. The modifications include the core model updates to StacNetworkWidget with new optional fields, the generated serialization code, parser updates to handle the new widgets, comprehensive test coverage for the new functionality, and example JSON files demonstrating the feature usage. No extraneous or unrelated changes are present; every modification serves the stated objective of enabling custom loading and error UI display in network-backed widgets.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

🧹 Nitpick comments (3)
packages/stac_core/test/widgets/network_widget/stac_network_widget_test.dart (1)

6-32: Consider validating widget content, not just presence.

The test correctly verifies that the optional widgets are not null, but could be more thorough by checking the actual widget types or properties to ensure correct deserialization.

Consider adding assertions like:

expect(widget.loadingWidget, isA<StacTextWidget>());
expect((widget.loadingWidget as StacTextWidget).data, equals('Loading...'));
packages/stac/lib/src/parsers/widgets/stac_network_widget/stac_network_widget_parser.dart (1)

18-35: Consider: Error parameter is available but not propagated to the widget.

The errorWidget callback receives an error parameter (Line 30), but this error information is not passed to the StacWidget during conversion. This means custom error widgets defined in JSON cannot access the actual error details (message, stack trace, etc.) to provide more specific error feedback.

This is a design limitation where the StacWidget model doesn't currently support passing runtime error context. While the current implementation is functional, you may want to:

  1. Document this limitation in the model's documentation
  2. Consider future enhancement where error details could be injected via a variable system or context
  3. For now, error widgets can only show static error messages

The current implementation is acceptable for the initial feature, but documenting this limitation would help users understand why their error widgets can't show specific error messages.

packages/stac_core/lib/widgets/network_widget/stac_network_widget.dart (1)

50-54: Well-documented optional fields.

The new loadingWidget and errorWidget fields are properly typed and documented.

Consider updating the class-level documentation examples (lines 15-36) to include the new optional parameters, showing how users can provide custom loading and error widgets. This would make the feature more discoverable.

Example addition to JSON example:

{
  "type": "networkWidget",
  "request": { ... },
  "loadingWidget": {
    "type": "circularProgressIndicator"
  },
  "errorWidget": {
    "type": "text",
    "data": "Failed to load"
  }
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36c3b60 and a20bddc.

📒 Files selected for processing (6)
  • examples/stac_gallery/assets/json/home_screen.json (1 hunks)
  • examples/stac_gallery/assets/json/network_widget_example.json (1 hunks)
  • packages/stac/lib/src/parsers/widgets/stac_network_widget/stac_network_widget_parser.dart (1 hunks)
  • packages/stac_core/lib/widgets/network_widget/stac_network_widget.dart (1 hunks)
  • packages/stac_core/lib/widgets/network_widget/stac_network_widget.g.dart (1 hunks)
  • packages/stac_core/test/widgets/network_widget/stac_network_widget_test.dart (1 hunks)
🔇 Additional comments (10)
examples/stac_gallery/assets/json/home_screen.json (1)

1443-1465: LGTM! Well-structured gallery entry.

The new list tile entry for "Stac Network Widget" is properly formatted and follows the existing patterns in the gallery. The icon choice and description clearly communicate the feature's purpose.

packages/stac_core/test/widgets/network_widget/stac_network_widget_test.dart (3)

34-52: LGTM! Proper validation of optional fields.

This test correctly verifies that the widget can be created without the optional loadingWidget and errorWidget fields, ensuring backward compatibility.


54-74: LGTM! Comprehensive serialization test.

The test thoroughly validates JSON serialization including both presence and content of the optional widget fields.


76-92: LGTM! Validates optional field serialization.

This test ensures that when optional widgets are not provided, they serialize as null, maintaining a clean JSON output.

packages/stac_core/lib/widgets/network_widget/stac_network_widget.g.dart (2)

14-19: LGTM! Proper nullable field deserialization.

The generated code correctly handles optional widget fields with appropriate null checks and uses StacWidget.fromJson for nested deserialization.


25-26: LGTM! Clean nullable field serialization.

The null-aware operator correctly handles serialization of optional widgets, ensuring they only call toJson() when non-null.

examples/stac_gallery/assets/json/network_widget_example.json (3)

11-16: LGTM! Appropriate test endpoint.

Using httpbin.org/delay/2 is an excellent choice for demonstrating the loading state, as it provides a reliable 2-second delay that users can observe.


17-36: LGTM! Clean loading state UI.

The loading widget follows best practices with a centered layout, progress indicator, appropriate spacing, and informative text. This provides a good user experience during network requests.


37-71: LGTM! User-friendly error state.

The error widget provides clear visual feedback with an appropriately colored error icon, bold heading, and actionable message. This offers good UX guidance for users encountering network issues.

packages/stac_core/lib/widgets/network_widget/stac_network_widget.dart (1)

41-45: LGTM! Clean constructor design.

The constructor properly defines the new optional parameters while maintaining the required request field. The parameter ordering and naming are consistent with Dart conventions.

@Sharath-a26
Copy link
Author

@coderabbitai help

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
    • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
    • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@Sharath-a26
Copy link
Author

@coderabbitai generate docstrings

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Caution

Docstrings generation - FAILED

No docstrings were generated.

@Sharath-a26
Copy link
Author

@coderabbitai generate docstrings

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@divyanshub024
Copy link
Member

@Sharath-a26 Can you please sign the CLA @CLAassistant

Comment on lines +21 to +35
loadingWidget: model.loadingWidget == null
? null
: (ctx) => StacService.fromStacWidget(
widget: model.loadingWidget!,
context: ctx,
) ??
const SizedBox(),
errorWidget: model.errorWidget == null
? null
: (ctx, error) => StacService.fromStacWidget(
widget: model.errorWidget!,
context: ctx,
) ??
const SizedBox(),
);
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the parse extension method instead from StacWidgetParser. Like

loadingWidget: model.loadingWidget?.parse(context),
errorWidget: model.errorWidget?.parse(context),

@@ -0,0 +1,95 @@
import 'package:flutter_test/flutter_test.dart';
Copy link
Member

Choose a reason for hiding this comment

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

Can we skip this test for now? It will be added again when we include full widget testing.

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.

feat: Add loader and error widget support to Stac networkWidget

3 participants