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

331

Use an IgnorePointer

InkWell(
  child: Row (
    children: <Widget> [
      IgnorePointer(
        child: SelectableText(...)
     )
    ]
  ),
  onTap: () => doSth();
)
Share:
331
S-Man
Author by

S-Man

Author Advanced PostgreSQL Querying ISBN 978-3752967340

Updated on December 18, 2022

Comments

  • S-Man
    S-Man over 1 year

    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();
    )
    
    • Darish
      Darish about 4 years
      @S-Man are you trying to just disable the TextField by catching tap events by InkWell onTap method?
    • S-Man
      S-Man about 4 years
      @Darish Argh... Not TextField, of course. It's a Text(A SelectableTextin this special case)... Sorry for confusion, changed the question
    • NoobN3rd
      NoobN3rd about 4 years
      Are You looking for AbsorbPointer?
  • S-Man
    S-Man about 4 years
    This would ignore the onPressed() events of the Button widget, which is a sibling of the Text widget (see Edit in the question)
  • Omar Fayad
    Omar Fayad about 4 years
    just remove behavior: HitTestBehavior.opaque, it should work
  • S-Man
    S-Man about 4 years
    This made it! Thanks!