Skip to content

Conversation

@Potatomonsta
Copy link
Contributor

@Potatomonsta Potatomonsta commented Dec 10, 2025

Description

This PR adds support for custom loading and error widgets in the StacNetworkWidget. Users can now provide optional loadingWidget and errorWidget properties that will be displayed during the network request lifecycle.

Changes:

  • Added loadingWidget and errorWidget as optional StacWidget? fields to StacNetworkWidget
  • Updated StacNetworkWidgetParser to parse these widgets and pass them to Stac.fromNetwork as builder functions
  • Updated documentation with Dart and JSON examples showing how to use the new features
  • Generated JSON serialization code for the new fields

Example Usage:

StacNetworkWidget(
  request: StacNetworkRequest(
    url: 'https://example.com/data',
    method: 'get',
  ),
  loadingWidget: StacCenter(
    child: StacCircularProgressIndicator(),
  ),
  errorWidget: StacCenter(
    child: StacText(data: 'Failed to load'),
  ),
)
{
  "type": "networkWidget",
  "request": {
    "actionType": "networkRequest",
    "url": "https://example.com/data",
    "method": "get"
  },
  "loadingWidget": {
    "type": "center",
    "child": {
      "type": "circularProgressIndicator"
    }
  },
  "errorWidget": {
    "type": "center",
    "child": {
      "type": "text",
      "data": "Failed to load"
    }
  }
}

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
    • Network widgets now support optional customizable loading and error state components
    • Users can define custom UI to display during network data loading operations
    • Error state presentation can be tailored to application requirements
    • Enhanced control over network request visual feedback

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

Add optional loadingWidget and errorWidget fields to StacNetworkWidget
to allow custom widgets to be displayed during network request states.

- Add loadingWidget and errorWidget as optional StacWidget? fields
- Update StacNetworkWidgetParser to parse and pass widgets to Stac.fromNetwork
- Update documentation with examples showing loading and error states
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 10, 2025

Walkthrough

The pull request extends StacNetworkWidget to support optional customizable loading and error widgets. Two new optional fields (loadingWidget and errorWidget) are added to the widget class, the parser is updated to instantiate these widgets when present, and the JSON serialization layer is updated to handle the new fields.

Changes

Cohort / File(s) Change Summary
StacNetworkWidget definition
packages/stac_core/lib/widgets/network_widget/stac_network_widget.dart, packages/stac_core/lib/widgets/network_widget/stac_network_widget.g.dart
Added optional loadingWidget and errorWidget parameters to constructor. Updated field documentation and JSON serialization examples. Generated code updated to deserialize/serialize the new nullable fields via StacWidget.fromJson and toJson.
StacNetworkWidget parser
packages/stac/lib/src/parsers/widgets/stac_network_widget/stac_network_widget_parser.dart
Updated imports and parser logic to handle optional loadingWidget and errorWidget from the model. Parser now calls parse(context) on loadingWidget when present (defaults to centered CircularProgressIndicator), and parse(context, error) on errorWidget when present (defaults to null when absent).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify that optional widget parsing logic correctly integrates with Stac.fromNetwork configuration
  • Confirm JSON serialization/deserialization handles nullable StacWidget fields correctly
  • Validate that default widget behavior (CircularProgressIndicator for loading, null for error) matches intended design

Poem

🐰 Hopping through networks with widgets so fine,
Loaders and errors now align,
Customizable UI at last takes flight—
STAC fragments load just right! ✨📡

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main change: adding loading and error widget support to StacNetworkWidget.
Linked Issues check ✅ Passed The PR fully implements the objective from issue #243: enabling StacNetworkWidget to display loader and error widgets when fetching remote Stac JSON.
Out of Scope Changes check ✅ Passed All changes are directly related to adding loadingWidget and errorWidget support to StacNetworkWidget as required by the linked issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mn/network-widget-loader-error

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 (1)
packages/stac/lib/src/parsers/widgets/stac_network_widget/stac_network_widget_parser.dart (1)

19-31: Builder wiring and null-handling look good; consider minor cleanup and confirm default error behavior

  • The loading builder correctly:
    • Uses model.loadingWidget!.parse(context) when present, and
    • Falls back to Center(CircularProgressIndicator()) both when the model is absent and when parsing returns null.
  • The error builder correctly:
    • Uses model.errorWidget!.parse(context) ?? const SizedBox() when a custom error widget is provided, and
    • Defers to Stac.fromNetwork’s default error handling when no custom error is configured (errorWidget: null).

Two small follow‑ups:

  • The error parameter is unused; using _ instead will avoid analyzer warnings and makes intent clearer:
-      errorWidget: model.errorWidget != null
-          ? (context, error) =>
-                model.errorWidget!.parse(context) ?? const SizedBox()
+      errorWidget: model.errorWidget != null
+          ? (context, _) =>
+                model.errorWidget!.parse(context) ?? const SizedBox()
           : null,
  • The docs on StacNetworkWidget.errorWidget say that when not provided, an empty SizedBox is shown on error. That now relies on Stac.fromNetwork’s internal default when errorWidget is null. Please just double‑check that default still matches the documented behavior.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4ebbca and c39e95b.

📒 Files selected for processing (3)
  • packages/stac/lib/src/parsers/widgets/stac_network_widget/stac_network_widget_parser.dart (2 hunks)
  • packages/stac_core/lib/widgets/network_widget/stac_network_widget.dart (3 hunks)
  • packages/stac_core/lib/widgets/network_widget/stac_network_widget.g.dart (1 hunks)
⏰ 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: analyze
🔇 Additional comments (4)
packages/stac/lib/src/parsers/widgets/stac_network_widget/stac_network_widget_parser.dart (1)

1-3: Material import matches new default loader usage

Switching to material.dart is appropriate now that CircularProgressIndicator is used as the default loader; the added stac_widget_parser import is also needed for model.loadingWidget!.parse(context) / model.errorWidget!.parse(context).

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

11-12: Docs and examples clearly describe new loading/error widget support

The updated class and JSON examples accurately show how to configure loadingWidget and errorWidget via both Dart and JSON. They align with the parser behavior (wrapping a centered CircularProgressIndicator for loading and a centered Text for error).

Also applies to: 22-27, 41-54


61-69: Model shape and field docs align with parser and serialization

  • The constructor signature StacNetworkWidget({ required this.request, this.loadingWidget, this.errorWidget }) matches the new JSON fields and the parser’s usage.
  • Using final StacWidget? loadingWidget / errorWidget is consistent with treating these as optional, serializable widget fragments.
  • The doc comments for loadingWidget (“default loading indicator”) and errorWidget (“empty SizedBox on error”) match what the parser plus Stac.fromNetwork are implementing, assuming the default error behavior in Stac.fromNetwork remains an empty widget.

No changes needed here; the core model is consistent with the rest of the PR.

Also applies to: 72-74, 76-85

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

14-19: Generated JSON mapping for loading/error widgets is consistent

Deserialization and serialization for loadingWidget and errorWidget correctly:

  • Treat the fields as nullable, and
  • Delegate to StacWidget.fromJson / .toJson().

This matches the updated StacNetworkWidget constructor and field types. Since this is generated code, no manual changes are needed.

Also applies to: 25-26

@divyanshub024 divyanshub024 merged commit 460a4c1 into dev Dec 11, 2025
6 checks passed
@divyanshub024 divyanshub024 deleted the mn/network-widget-loader-error branch December 11, 2025 13:23
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