Flutter – InkWell not reacting to onTap inside Flexible

Issue

I am trying to figure out, why the onTap() method inside my InkWell is not working. The InkWell widget is inside a Flexible widget. This Flexible widget is also inside
a Row.

Here is my code:

TextEditingController controller = new TextEditingController();

@override
void dispose(){
    super.dispose();
    controller.dispose();
}

@override
    Widget build(BuildContext context) {
      return Card(        
        child: Container(          
          child: Row(
            children: <Widget>[
              Flexible(                
                child: InkWell(
                  onTap: () => print("Search"), //Is not printing anything
                  child: TextField(                    
                    controller: controller,
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: "Searching..."
                    ),                 
                  ),
                ),
              )
            ],
          ),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(
              Radius.circular(8.0)
            ),
          ),
        ),     
      );
    }

I do not know how to solve my problem. It would be awesome, if somebody would be able to solve it XD.

Solution

Wrapping IgnorePointer inside the Inkwell’s child will solve this:

Widget build(BuildContext context) {
    return Card(
      child: Container(
        child: Row(
          children: <Widget>[
            Flexible(
              child: InkWell(
                onTap: () => print("Search"), //Is not printing anything
                child: IgnorePointer(
                  child: TextField(
                    controller: controller,
                    decoration: InputDecoration(
                        border: InputBorder.none,
                        hintText: "Searching..."
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(
              Radius.circular(8.0)
          ),
        ),
      ),
    );
  }

Answered By – anmol.majhail

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.