recurseKey static method

List<Map<String, dynamic>> recurseKey(
  1. BuildContext element,
  2. double pixRatio,
  3. int screenWidth,
  4. int screenHeight,
)

Implementation

static List<Map<String, dynamic>> recurseKey(BuildContext element,
    double pixRatio, int screenWidth, int screenHeight) {
  List<Map<String, dynamic>> list = [];
  try {
    element.visitChildElements((element) {
      try {
        String? key = element.widget.key?.toString();
        if (key != null && key.contains("<'") && key.contains("'>") && key.startsWith("[<'")) {
          RenderBox box = element.findRenderObject() as RenderBox;
          Offset position = box.localToGlobal(Offset.zero);
          if (isWithinBounds(
              element, position, pixRatio, screenWidth, screenHeight) && visibilityMap[key] == 100.0) {
            Map<String, dynamic> newPosition = {};
            Map<String, dynamic> elementObj = {};
            newPosition['x'] = ((position.dx * pixRatio) + 0.6).round();
            newPosition['y'] = ((position.dy * pixRatio) + 0.6).round();
            newPosition['width'] =
                ((element.size?.width ?? 0) * pixRatio).round();
            newPosition['height'] =
                ((element.size?.height ?? 0) * pixRatio).round();
            elementObj['clientElementId'] = key;
            elementObj['position'] = newPosition;
            list.add(elementObj);
          }
        }
        list.addAll(recurseKey(element, pixRatio, screenWidth, screenHeight));
      } catch (e) {
        debugPrint("Error in vCElements: $e");
      }
    });
  } catch (e) {
    debugPrint("Error in rKey: $e");
  }
  return list;
}