Skip to content
Merged
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
22 changes: 22 additions & 0 deletions examples/stac_gallery/assets/json/dynamic_view_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@
"url": "https://dummyjson.com/users/1",
"method": "get"
},
"loaderWidget": {
"type": "center",
"child": {
"type": "column",
"children": [
{
"type": "text",
"data": "Loading..."
},
{
"type": "circularProgressIndicator"
}
]
}
},
"errorWidget": {
"type": "center",
"child": {
"type": "text",
"data": "Error fetching user profile"
}
},
"template": {
"type": "column",
"children": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:stac/src/parsers/actions/stac_network_request/stac_network_request.dart';
import 'package:stac/stac.dart';

export 'stac_dynamic_view_parser.dart';

Expand All @@ -15,6 +15,8 @@ abstract class StacDynamicView with _$StacDynamicView {
@Default('') String targetPath,
required Map<String, dynamic> template,
@Default('') String resultTarget,
StacWidget? loaderWidget,
StacWidget? errorWidget,
}) = _StacDynamicView;

factory StacDynamicView.fromJson(Map<String, dynamic> json) =>
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ class StacDynamicViewParser extends StacParser<StacDynamicView> {
future: _fetchData(context, model),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
return Stac.fromJson(model.loaderWidget, context) ??
const Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
Log.e(snapshot.error);
return const SizedBox();
return Stac.fromJson(model.errorWidget, context) ?? const SizedBox();
} else if (snapshot.hasData) {
final response = snapshot.data;
if (response != null) {
Expand Down Expand Up @@ -70,7 +71,8 @@ class StacDynamicViewParser extends StacParser<StacDynamicView> {
}
} catch (e) {
Log.e('Error parsing API response: $e');
return SizedBox();
return Stac.fromJson(model.errorWidget, context) ??
const SizedBox();
}
}
return const SizedBox();
Expand Down
Loading