findAppImages method

Map<String, List<Map<String, String>>> findAppImages(
  1. Map<String, dynamic> data,
  2. List<String> sectionsToDownload
)

Finds sections matching APP_ASSET_<sectionName> (or all if sectionsToDownload is empty)

Implementation

Map<String, List<Map<String, String>>> findAppImages(
    Map<String, dynamic> data, List<String> sectionsToDownload) {
  Map<String, List<Map<String, String>>> imageNodes = {};

  for (var page in data['document']['children'] ?? []) {
    for (var node in page['children'] ?? []) {
      if (!node['name'].startsWith('APP_ASSET_') ||
          node['type'] != 'SECTION') {
        continue;
      }

      String folderName = node['name'].replaceFirst('APP_ASSET_', '');

      // Only include specified sections (or all if empty)
      if (sectionsToDownload.isNotEmpty &&
          !sectionsToDownload.contains(folderName)) {
        continue;
      }

      imageNodes[folderName] = [];

      for (var child in node['children'] ?? []) {
        if (child['type'] == 'COMPONENT' &&
            child.containsKey('fills') &&
            child.containsKey('name')) {
          imageNodes[folderName]!.add({
            'id': child['id'],
            'name': child['name'],
          });
        }
      }
    }
  }

  return imageNodes;
}