From 01d5fd5669d00303659d0ab72ce9784783af57ea Mon Sep 17 00:00:00 2001 From: Till Friebe Date: Fri, 19 Mar 2021 10:07:01 +0100 Subject: [PATCH] Add hitTesting to allow changing click behavior in embeds This allows us to override the default behavior of clicking on images and thus solves PR #90. Now the only thing left to do is to use a RawGestureDetector in the EmbedBuilder to deactivate the previous behavior (by entering the GestureArena and always win). Explanation of the code: When a `PointerDownEvent` is received by the `GestureBinding` a hit test is performed to determine which HitTestTarget nodes are affected. For this the (I think) element tree is traversed downwards to find out which elements has been hit. To find out which elements were hit, the method `hitTestSelf` and `hitTestChildren` are used. Since the `hitTestChildren` method of TextLine has not been implemented yet, it has always returned false by default, which is why the hit test never arrived at the `embedBuilder`. With the code change, the hit is passed on and can be processed correctly in the embed. --- lib/widgets/text_line.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index ffe7ee93..a9260e8f 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -785,6 +785,11 @@ class RenderEditableTextLine extends RenderEditableBox { ); _cursorPainter.paint(context.canvas, effectiveOffset, position); } + + @override + bool hitTestChildren(BoxHitTestResult result, {Offset position}) { + return this._children.first.hitTest(result, position: position); + } } class _TextLineElement extends RenderObjectElement {