dd-sdk-flutter icon indicating copy to clipboard operation
dd-sdk-flutter copied to clipboard

Nested GestureDetector should take precedence over parent InkWell

Open a-h-mzd opened this issue 9 months ago • 3 comments

Describe the bug

When theres a GestureDetector down the widget tree which has its onTap set, it takes precedence over the InkWell higher up the tree. But this is not the case when it comes to RumUserActionAnnotation 👇🏼

Reproduction steps

final class TestWidget extends StatelessWidget {
  const TestWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return RumUserActionAnnotation(
      description: 'TestWidget',
      attributes: {'placement': 'parent'},
      child: InkWell(
        onTap: () => 'parent tapped',
        child: Container(
          width: 100,
          height: 100,
          color: Colors.white,
          alignment: Alignment.center,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text('parent'),
              RumUserActionAnnotation(
                description: 'TestWidget - Child',
                attributes: {'placement': 'child'},
                child: GestureDetector(
                  onTap: () => 'child tapped',
                  child: Text('child'),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

SDK logs

No response

Expected behavior

No response

Affected SDK versions

2.10.2

Latest working SDK version

No response

Did you confirm if the latest SDK version fixes the bug?

Yes

Flutter Version

No response

Setup Type

No response

Device Information

No response

Other relevant information

No response

a-h-mzd avatar Apr 09 '25 14:04 a-h-mzd

👍 I'll look into this. I need to double check but I think InkWell actually has a GestureDetector built into it, which is why it's considered the "better" choice than a GestureDetector further down the tree.

fuzzybinary avatar Apr 10 '25 14:04 fuzzybinary

You're right — InkWell does have a GestureDetector built into it, but when its child is also a GestureDetector, the onTap of the child is triggered instead. This means the child takes precedence over the parent in handling gestures.

a-h-mzd avatar Apr 10 '25 14:04 a-h-mzd

Yes, this is more of an issue of how we detect what to put in the description. If there are no user specified GestureDetectors under the InkWell, than we need to scan the children of the InkWell to determine "what" you tapped, not its nested GestureDetector.

fuzzybinary avatar Apr 10 '25 14:04 fuzzybinary