diff --git a/lib/generation/generators/symbols/pb_instancesym_gen.dart b/lib/generation/generators/symbols/pb_instancesym_gen.dart index df684dd8..620dcbbb 100644 --- a/lib/generation/generators/symbols/pb_instancesym_gen.dart +++ b/lib/generation/generators/symbols/pb_instancesym_gen.dart @@ -22,7 +22,7 @@ class PBSymbolInstanceGenerator extends PBGenerator { String generate( PBIntermediateNode source, GeneratorContext generatorContext) { if (source is PBSharedInstanceIntermediateNode) { - var method_signature = source.functionCallName.pascalCase; + var method_signature = source.functionCallName?.pascalCase; if (method_signature == null) { log.error(' Could not find master name on: $source'); return 'Container(/** This Symbol was not found **/)'; diff --git a/lib/generation/prototyping/pb_prototype_linker_service.dart b/lib/generation/prototyping/pb_prototype_linker_service.dart index 8c3cdf48..b895b8fa 100644 --- a/lib/generation/prototyping/pb_prototype_linker_service.dart +++ b/lib/generation/prototyping/pb_prototype_linker_service.dart @@ -33,6 +33,9 @@ class PBPrototypeLinkerService { while (stack.isNotEmpty) { var currentNode = stack.removeLast(); + if (currentNode == null) { + continue; + } currentNode.attributes.forEach((attribute) { attribute.attributeNodes.forEach(stack.add); }); diff --git a/lib/input/figma/entities/layers/group.dart b/lib/input/figma/entities/layers/group.dart index e664925e..8723bab1 100644 --- a/lib/input/figma/entities/layers/group.dart +++ b/lib/input/figma/entities/layers/group.dart @@ -106,7 +106,9 @@ class Group extends FigmaFrame implements AbstractFigmaNodeFactory, Image { this.prototypeNodeUUID = tempPrototypeID; } - boundaryRectangle = fitFrame(); + if (children != null && children.isNotEmpty) { + boundaryRectangle = fitFrame(); + } children.clear(); diff --git a/lib/input/figma/helper/figma_asset_processor.dart b/lib/input/figma/helper/figma_asset_processor.dart index c980f5e8..b600be8b 100644 --- a/lib/input/figma/helper/figma_asset_processor.dart +++ b/lib/input/figma/helper/figma_asset_processor.dart @@ -63,41 +63,46 @@ class FigmaAssetProcessor extends AssetProcessingService { {bool writeAsFile = true}) async { // Call Figma API to get Image link return Future(() async { - var response = await APICallService.makeAPICall( - 'https://api.figma.com/v1/images/${MainInfo().figmaProjectID}?ids=${uuids.join(',')}&use_absolute_bounds=true', - MainInfo().figmaKey); - - if (response != null && - response.containsKey('images') && - response['images'] != null && - response['images'].values.isNotEmpty) { - Map images = response['images']; - // Download the images - for (var entry in images.entries) { - if (entry?.value != null && entry?.value?.isNotEmpty) { - response = await http.get(entry.value).then((imageRes) async { - // Check if the request was successful - if (imageRes == null || imageRes.statusCode != 200) { - log.error('Image ${entry.key} was not processed correctly'); - } - - if (writeAsFile) { - var file = File('${MainInfo().outputPath}pngs/${entry.key}.png' - .replaceAll(':', '_')) - ..createSync(recursive: true); - file.writeAsBytesSync(imageRes.bodyBytes); - } else { - await super.uploadToStorage(imageRes.bodyBytes, entry.key); - } - // TODO: Only print out when verbose flag is active - // log.debug('File written to following path ${file.path}'); - }).catchError((e) { - MainInfo().sentry.captureException(exception: e); - log.error(e.toString()); - }); + List> uuidsChunks = _listToChunks(uuids, 50); + + for (var list in uuidsChunks) { + var response = await APICallService.makeAPICall( + 'https://api.figma.com/v1/images/${MainInfo().figmaProjectID}?ids=${list.join(',')}&use_absolute_bounds=true', + MainInfo().figmaKey); + + if (response != null && + response.containsKey('images') && + response['images'] != null && + response['images'].values.isNotEmpty) { + Map images = response['images']; + // Download the images + for (var entry in images.entries) { + if (entry?.value != null && entry?.value?.isNotEmpty) { + response = await http.get(entry.value).then((imageRes) async { + // Check if the request was successful + if (imageRes == null || imageRes.statusCode != 200) { + log.error('Image ${entry.key} was not processed correctly'); + } + + if (writeAsFile) { + var file = File( + '${MainInfo().outputPath}pngs/${entry.key}.png' + .replaceAll(':', '_')) + ..createSync(recursive: true); + file.writeAsBytesSync(imageRes.bodyBytes); + } else { + await super.uploadToStorage(imageRes.bodyBytes, entry.key); + } + // TODO: Only print out when verbose flag is active + // log.debug('File written to following path ${file.path}'); + }).catchError((e) { + MainInfo().sentry.captureException(exception: e); + log.error(e.toString()); + }); + } } + return response; } - return response; } }); } @@ -107,4 +112,24 @@ class FigmaAssetProcessor extends AssetProcessingService { _addImagesToQueue(uuids.keys.toList()); await processImageQueue(writeAsFile: false); } + + List _listToChunks(List currentList, int chuckSize) { + var temp = []; + var counter = 0; + // ignore: omit_local_variable_types + List> listOnChunks = + currentList.fold>>([], (newList, i) { + counter++; + if (temp.length < chuckSize) { + temp.add(i); + } + if (temp.length >= chuckSize || currentList.length == counter) { + var newValue = List.from(temp); + newList.add(newValue); + temp.clear(); + } + return newList; + }); + return listOnChunks; + } } diff --git a/lib/interpret_and_optimize/entities/inherited_scaffold.dart b/lib/interpret_and_optimize/entities/inherited_scaffold.dart index 841bcc5e..91d76c82 100644 --- a/lib/interpret_and_optimize/entities/inherited_scaffold.dart +++ b/lib/interpret_and_optimize/entities/inherited_scaffold.dart @@ -119,10 +119,12 @@ class InheritedScaffold extends PBVisualIntermediateNode @override void alignChild() { - var align = - InjectedAlign(topLeftCorner, bottomRightCorner, currentContext, ''); - align.addChild(child); - align.alignChild(); - child = align; + if (child != null) { + var align = + InjectedAlign(topLeftCorner, bottomRightCorner, currentContext, ''); + align.addChild(child); + align.alignChild(); + child = align; + } } } diff --git a/lib/interpret_and_optimize/entities/inherited_text.dart b/lib/interpret_and_optimize/entities/inherited_text.dart index d3135a06..47b01a82 100644 --- a/lib/interpret_and_optimize/entities/inherited_text.dart +++ b/lib/interpret_and_optimize/entities/inherited_text.dart @@ -49,6 +49,9 @@ class InheritedText extends PBVisualIntermediateNode generator = PBTextGen(); text = (originalRef as Text).content; + if (text.contains('\$')) { + text = _sanitizeText(text); + } fontSize = originalRef.style.textStyle.fontDescriptor.fontSize; auxiliaryData.color = toHex(originalRef.style.textStyle.fontColor); fontName = originalRef.style.textStyle.fontDescriptor.fontName; @@ -68,6 +71,10 @@ class InheritedText extends PBVisualIntermediateNode } } + String _sanitizeText(String text) { + return text.replaceAll('\$', '\\\$'); + } + @override void addChild(PBIntermediateNode node) { assert(true, 'Adding a child to InheritedText should not be possible.'); diff --git a/lib/interpret_and_optimize/services/pb_alignment_generation_service.dart b/lib/interpret_and_optimize/services/pb_alignment_generation_service.dart index 5f52ec71..65f0e7a0 100644 --- a/lib/interpret_and_optimize/services/pb_alignment_generation_service.dart +++ b/lib/interpret_and_optimize/services/pb_alignment_generation_service.dart @@ -44,6 +44,9 @@ class PBAlignGenerationService implements PBGenerationService { } else if (currentIntermediateNode is PBLayoutIntermediateNode) { currentIntermediateNode.alignChildren(); } + if (currentIntermediateNode == null) { + continue; + } currentIntermediateNode.attributes.forEach((attribute) { attribute.attributeNodes.forEach((node) {