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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ abstract class StacDynamicView with _$StacDynamicView {
@Default('') String targetPath,
required Map<String, dynamic> template,
@Default('') String resultTarget,
Map<String, dynamic>? emptyTemplate,
StacWidget? loaderWidget,
StacWidget? errorWidget,
}) = _StacDynamicView;
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 @@ -55,6 +55,13 @@ class StacDynamicViewParser extends StacParser<StacDynamicView> {
Log.d("data: $data");

if (data != null) {
// Check if data is an empty list and we have an empty template
if (_isEmptyList(data) && model.emptyTemplate != null) {
Log.d("Data is empty list, using empty template");
return Stac.fromJson(model.emptyTemplate!, context) ??
const SizedBox();
}

// Prepare data for template based on resultTarget
final dataForTemplate = model.resultTarget.isNotEmpty
? {model.resultTarget: data}
Expand Down Expand Up @@ -173,6 +180,16 @@ class StacDynamicViewParser extends StacParser<StacDynamicView> {
}

if (listForIteration != null) {
// Check if the list is empty
if (listForIteration is List && listForIteration.isEmpty) {
Log.d(
"List for iteration is empty, removing itemTemplate and children");
resolvedTemplate.remove(itemTemplateKey);
// Clear children or set to empty list
resolvedTemplate['children'] = [];
return resolvedTemplate;
}

resolvedTemplate
.remove(itemTemplateKey); // Remove from outer template structure
final processedChildItems = <Map<String, dynamic>>[];
Expand Down Expand Up @@ -279,4 +296,32 @@ class StacDynamicViewParser extends StacParser<StacDynamicView> {
}
return template;
}

/// Helper method to check if the data represents an empty list.
/// This method checks various scenarios:
/// 1. Direct empty list
/// 2. Empty list at the target path (if resultTarget is specified)
/// 3. Empty list in nested data structures
bool _isEmptyList(dynamic data) {
// Direct empty list check
if (data is List && data.isEmpty) {
return true;
}

// If data is a Map, check if it contains empty lists
if (data is Map) {
// Check all values in the map for empty lists
for (final value in data.values) {
if (value is List && value.isEmpty) {
return true;
}
// Recursively check nested maps
if (value is Map && _isEmptyList(value)) {
return true;
}
}
}

return false;
}
}
Loading