-
-
Notifications
You must be signed in to change notification settings - Fork 85
feat: add loading and error widget support for StacNetworkWidget #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
WalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ 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.
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 returnsnull.- 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
errorparameter 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.errorWidgetsay that when not provided, an emptySizedBoxis shown on error. That now relies onStac.fromNetwork’s internal default whenerrorWidgetisnull. Please just double‑check that default still matches the documented behavior.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 usageSwitching to
material.dartis appropriate now thatCircularProgressIndicatoris used as the default loader; the addedstac_widget_parserimport is also needed formodel.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 supportThe updated class and JSON examples accurately show how to configure
loadingWidgetanderrorWidgetvia both Dart and JSON. They align with the parser behavior (wrapping a centeredCircularProgressIndicatorfor loading and a centeredTextfor 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/errorWidgetis consistent with treating these as optional, serializable widget fragments.- The doc comments for
loadingWidget(“default loading indicator”) anderrorWidget(“empty SizedBox on error”) match what the parser plusStac.fromNetworkare implementing, assuming the default error behavior inStac.fromNetworkremains 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 consistentDeserialization and serialization for
loadingWidgetanderrorWidgetcorrectly:
- Treat the fields as nullable, and
- Delegate to
StacWidget.fromJson/.toJson().This matches the updated
StacNetworkWidgetconstructor and field types. Since this is generated code, no manual changes are needed.Also applies to: 25-26
Description
This PR adds support for custom loading and error widgets in the
StacNetworkWidget. Users can now provide optionalloadingWidgetanderrorWidgetproperties that will be displayed during the network request lifecycle.Changes:
loadingWidgetanderrorWidgetas optionalStacWidget?fields toStacNetworkWidgetStacNetworkWidgetParserto parse these widgets and pass them toStac.fromNetworkas builder functionsExample Usage:
{ "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
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.