Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:stac/src/framework/framework.dart';
import 'package:stac/src/parsers/core/stac_widget_parser.dart';
import 'package:stac_core/stac_core.dart';
import 'package:stac_framework/stac_framework.dart';

Expand All @@ -15,6 +16,16 @@ class StacNetworkWidgetParser extends StacParser<StacNetworkWidget> {

@override
Widget parse(BuildContext context, StacNetworkWidget model) {
return Stac.fromNetwork(context: context, request: model.request);
return Stac.fromNetwork(
context: context,
request: model.request,
loadingWidget: model.loadingWidget != null
Copy link
Member

Choose a reason for hiding this comment

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

I think we should have some default loading widget

? (context) => model.loadingWidget!.parse(context) ?? const SizedBox()
: null,
errorWidget: model.errorWidget != null
? (context, error) =>
model.errorWidget!.parse(context) ?? const SizedBox()
: null,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ part 'stac_network_widget.g.dart';
/// A Stac model representing a network-driven widget.
///
/// This widget triggers a [StacNetworkRequest] to fetch a Stac UI JSON from a
/// URL and renders it.
/// URL and renders it. Optionally, you can provide custom loading and error
/// widgets to display during the network request lifecycle.
///
/// {@tool snippet}
/// Dart Example:
Expand All @@ -18,6 +19,12 @@ part 'stac_network_widget.g.dart';
/// url: 'https://example.com/data',
/// method: 'get',
/// ),
/// loadingWidget: StacCenter(
/// child: StacCircularProgressIndicator(),
/// ),
/// errorWidget: StacCenter(
/// child: StacText(data: 'Failed to load'),
/// ),
/// )
/// ```
/// {@end-tool}
Expand All @@ -31,18 +38,51 @@ part 'stac_network_widget.g.dart';
/// "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"
/// }
/// }
/// }
/// ```
/// {@end-tool}
@JsonSerializable()
class StacNetworkWidget extends StacWidget {
/// Creates a [StacNetworkWidget].
const StacNetworkWidget({required this.request});
///
/// The [request] parameter is required and defines the network request
/// to execute. The [loadingWidget] and [errorWidget] parameters are
/// optional and allow you to customize the loading and error states.
const StacNetworkWidget({
required this.request,
this.loadingWidget,
this.errorWidget,
});

/// The network request to execute.
///
/// This defines the URL, method, headers, and body for the network request.
final StacNetworkRequest request;

/// Optional widget to display while the network request is in progress.
///
/// If not provided, a default loading indicator is shown.
final StacWidget? loadingWidget;

/// Optional widget to display when the network request fails.
///
/// If not provided, an empty [SizedBox] is shown on error.
final StacWidget? errorWidget;

/// Widget type identifier.
@override
String get type => WidgetType.networkWidget.name;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading