Skip to content

Commit 3cf4573

Browse files
committed
feat: add custom loader and error widget support to StacDynamicView
1 parent cad3f75 commit 3cf4573

File tree

5 files changed

+113
-16
lines changed

5 files changed

+113
-16
lines changed

examples/stac_gallery/assets/json/dynamic_view_example.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@
1313
"url": "https://dummyjson.com/users/1",
1414
"method": "get"
1515
},
16+
"loaderWidget": {
17+
"type": "center",
18+
"child": {
19+
"type": "column",
20+
"children": [
21+
{
22+
"type": "text",
23+
"data": "Loading..."
24+
},
25+
{
26+
"type": "circularProgressIndicator"
27+
}
28+
]
29+
}
30+
},
31+
"errorWidget": {
32+
"type": "center",
33+
"child": {
34+
"type": "text",
35+
"data": "Error fetching user profile"
36+
}
37+
},
1638
"template": {
1739
"type": "column",
1840
"children": [

packages/stac/lib/src/parsers/widgets/stac_dynamic_view/stac_dynamic_view.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:freezed_annotation/freezed_annotation.dart';
2-
import 'package:stac/src/parsers/actions/stac_network_request/stac_network_request.dart';
2+
import 'package:stac/stac.dart';
33

44
export 'stac_dynamic_view_parser.dart';
55

@@ -15,6 +15,8 @@ abstract class StacDynamicView with _$StacDynamicView {
1515
@Default('') String targetPath,
1616
required Map<String, dynamic> template,
1717
@Default('') String resultTarget,
18+
StacWidget? loaderWidget,
19+
StacWidget? errorWidget,
1820
}) = _StacDynamicView;
1921

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

packages/stac/lib/src/parsers/widgets/stac_dynamic_view/stac_dynamic_view.freezed.dart

Lines changed: 81 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/stac/lib/src/parsers/widgets/stac_dynamic_view/stac_dynamic_view.g.dart

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/stac/lib/src/parsers/widgets/stac_dynamic_view/stac_dynamic_view_parser.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class StacDynamicViewParser extends StacParser<StacDynamicView> {
2626
future: _fetchData(context, model),
2727
builder: (context, snapshot) {
2828
if (snapshot.connectionState == ConnectionState.waiting) {
29-
return const Center(child: CircularProgressIndicator());
29+
return Stac.fromJson(model.loaderWidget, context) ?? const Center(child: CircularProgressIndicator());
3030
} else if (snapshot.hasError) {
3131
Log.e(snapshot.error);
32-
return const SizedBox();
32+
return Stac.fromJson(model.errorWidget, context) ?? const SizedBox();
3333
} else if (snapshot.hasData) {
3434
final response = snapshot.data;
3535
if (response != null) {
@@ -70,7 +70,7 @@ class StacDynamicViewParser extends StacParser<StacDynamicView> {
7070
}
7171
} catch (e) {
7272
Log.e('Error parsing API response: $e');
73-
return SizedBox();
73+
return Stac.fromJson(model.errorWidget, context) ?? const SizedBox();
7474
}
7575
}
7676
return const SizedBox();

0 commit comments

Comments
 (0)