在RenderBox HitTest之后添加到对象

时间:2019-08-10 02:23:38

标签: flutter flutter-layout

我想在进行点击测试后将“定位的”小部件添加到相对位置。路径如下Listener -> ListView -> SizedBox -> Container

我试图访问返回路径中的变量,但是有关如何执行操作的文档受到限制。

    Listener listener = new Listener(
        onPointerUp: (PointerUpEvent event) {
                      print('${event.position}');
            final RenderBox box = context.findRenderObject();
                          final Offset localOffset =
                  box.globalToLocal(event.position);
                 var res = BoxHitTestResult();
                 box.hitTest(res, position:localOffset);
                 for(var r in res.path)
                 {
                   print(r);
                 }

        },
        child: Container()
);
RenderConstrainedBox#fffda relayoutBoundary=up27 dart_sdk.js:19110:15
RenderRepaintBoundary#3afc3 relayoutBoundary=up26 dart_sdk.js:19110:15
RenderIndexedSemantics#57986 relayoutBoundary=up25 dart_sdk.js:19110:15
RenderSliverList#46e30 relayoutBoundary=up24 dart_sdk.js:19110:15
RenderPointerListener#b70ac relayoutBoundary=up19 dart_sdk.js:19110:15
RenderSemanticsGestureHandler#8224c relayoutBoundary=up18 dart_sdk.js:19110:15
RenderPointerListener#62c4e relayoutBoundary=up17 dart_sdk.js:19110:15
_RenderScrollSemantics#fc217 relayoutBoundary=up16 dart_sdk.js:19110:15
RenderRepaintBoundary#be170 relayoutBoundary=up15 dart_sdk.js:19110:15
RenderCustomPaint#385db relayoutBoundary=up14 dart_sdk.js:19110:15
RenderRepaintBoundary#3d0ab relayoutBoundary=up13 dart_sdk.js:19110:15
RenderRepaintBoundary#a3e3b relayoutBoundary=up12 dart_sdk.js:19110:15
RenderCustomPaint#83c0b relayoutBoundary=up11 dart_sdk.js:19110:15
RenderRepaintBoundary#c3ec5 relayoutBoundary=up10 dart_sdk.js:19110:15
RenderPadding#0cbae relayoutBoundary=up9 dart_sdk.js:19110:15
RenderDecoratedBox#760d1 relayoutBoundary=up8 dart_sdk.js:19110:15
RenderFlex#41bef relayoutBoundary=up7 dart_sdk.js:19110:15
RenderCustomMultiChildLayoutBox#939e4 relayoutBoundary=up6 dart_sdk.js:19110:15
_RenderInkFeatures#a1c5e relayoutBoundary=up5 dart_sdk.js:19110:15
RenderPhysicalModel#19c78 relayoutBoundary=up4 dart_sdk.js:19110:15
RenderPointerListener#e553e relayoutBoundary=up3 dart_sdk.js:19110:15
RenderSemanticsGestureHandler#dbe00 relayoutBoundary=up2 dart_sdk.js:19110:15
RenderPointerListener#0ce7e relayoutBoundary=up1

我希望能够直接访问和更改窗口小部件,或者在有问题的窗口小部件内部调用事件,将提供的位置转换为相对于该容器的位置,然后使用相对坐标添加定位的窗口小部件。 / p>

1 个答案:

答案 0 :(得分:0)

解决方案是将全局密钥附加到小部件,然后将其包装在提供密钥作为数据的元数据中。元数据似乎是从窗口小部件层到渲染引擎以及往回传递的主要方式。

    $entityManager = $this->getDoctrine()->getManager();
    $propertyData = $entityManager->getRepository('PropertyBundle:Property')->find(4);
    $propertyType = $propertyData->getPropertyTypeId();

    if($propertyData->getStatus() == 1) {
        $propertyData->setName('test1');
        $propertyType->setName('test1');
    } else if($propertyData->getStatus() == 2) {
        $propertyData->setName('test2');
        $propertyType->setName('test2');
    }

   if($propertyData->getStyle() == 1) {
       // only refresh $propertyType object
        $entityManager->refresh($propertyType) 
    }

然后,可以从命中测试访问元数据对象以附加全局密钥。

MetaData( 
          metaData: widget.key,  
          child: Container(
          height: 50,
          width: 50,
              ),
            ));

现在我们已经从渲染管道中找到了全局键,我们可以轻松地搜索包含键的地图或列表,以找到实际的小部件对象并根据需要进行更新。