S-Man
S-Man

Reputation: 23686

Ignore onTap() event for Text -> Take onTap() event of parent Row instead

I have a Row widget. This row has a Text as child (in this case, it is a SelectableText). The row is embedded into an InkWell widget for handling onTap() events. This works fine unless I tap the Text. In that case the InkWell onTap() event is not raising.

InkWell(
  child: Row (
    children: <Widget> [
      SelectableText(...)
    ]
  ),
  onTap: () => doSth();
)

Is it possible to ignore the Text for onTap() events? My workaround would be to add an onTap() event to the Text as well with the same code. But, in fact, I want to avoid this replication.


Edit: In fact, there's also a Button widget next to the Text widget. Its onPressed() event should work as expected, nevertheless.

InkWell(
  child: Row (
    children: <Widget> [
      SelectableText(...),
      Button(
        onPressed: () {...}
      )
    ]
  ),
  onTap: () => doSth();
)

Upvotes: 2

Views: 836

Answers (2)

Neeraj
Neeraj

Reputation: 2558

Use an IgnorePointer

InkWell(
  child: Row (
    children: <Widget> [
      IgnorePointer(
        child: SelectableText(...)
     )
    ]
  ),
  onTap: () => doSth();
)

Upvotes: 1

Omar Fayad
Omar Fayad

Reputation: 1793

Try this:

GestureDetector(
 // behavior: HitTestBehavior.opaque,
  onTap: () => doSth();
  child: Row(
    children: <Widget>[
      SelectableText(...),
    ],
  ),
),

Upvotes: 0

Related Questions