Flutter - InkWell not reacting to onTap inside Flexible

4,474

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)
          ),
        ),
      ),
    );
  }
Share:
4,474
Admin
Author by

Admin

Updated on December 07, 2022

Comments

  • Admin
    Admin over 1 year

    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.

  • anmol.majhail
    anmol.majhail over 5 years
    No Issue, Thanks
  • Ali Akber
    Ali Akber about 3 years
    Inkwell wasn't working for me inside a bottom sheet, but adding this worked. Could someone explain why this happens and why this solution works?
  • Ali Yar Khan
    Ali Yar Khan almost 3 years
    In mine case, it is not working working inside stack -> positioned -> row -> container ... adding the ignore pointer also doesn't benefit. What can be the issue ?
  • Chris
    Chris over 2 years
    Thanks! That was driving me craaaaazy ...