Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Detect TexField on tap

Tags:

flutter

dart

I maked a flutter app in windows and all works, but when i tried to compile to iOS throw a unexpected error. In the Textfield detects that the 'onTap' isn´t a a correct parameter. I don´t know what happens, in windows doesn´t return this error. Anyway. anybody know how fix this and what is the correct way to detect 'onTap' on texfield?

 new Container(
          color: Colors.blue[300],
          child: new Padding(
            padding: const EdgeInsets.all(8.0),
            child: new Card(
              child: new ListTile(
                leading: new Icon(Icons.search),
                title: new TextField(
                  onTap: () { <--- The named parameter 'onTap' isn´t defined
                    Navigator.push(
                        context,

UPDATE

I tried this but doesn´t work

 title: new GestureDetector(
            child: new TextField(
          controller: searchController,
          decoration: new InputDecoration(
              hintText: 'Buscar parcela', border: InputBorder.none),
        )),
        onTap: () {
          Navigator.push(
              context,
              new MaterialPageRoute(
                  builder: (context) => new EstatesPage(
                      parcela: widget.parcela,
                      dropdownItem: dropdownSelection)));
        },

UPDATE 2: SOLUTION

I updated flutter and brew. The error disappeared.

like image 733
El Hombre Sin Nombre Avatar asked Mar 05 '23 22:03

El Hombre Sin Nombre


1 Answers

you can wrap your textfield in IgnorePointer widget. It disables all the gestures on its children. This will make gesture detector work.

title: new GestureDetector(
            child: new IgnorePointer (
                child: new TextField(
              controller: searchController,
              decoration: new InputDecoration(
                  hintText: 'Buscar parcela', border: InputBorder.none),
            ))),
        onTap: () {
          Navigator.push(
              context,
              new MaterialPageRoute(
                  builder: (context) => new EstatesPage(
                      parcela: widget.parcela,
                      dropdownItem: dropdownSelection)));
        },
like image 183
Kushal Jain Avatar answered Mar 18 '23 23:03

Kushal Jain