代码之家  ›  专栏  ›  技术社区  ›  El Hombre Sin Nombre

颤振-检测抽头上的TexField

  •  0
  • El Hombre Sin Nombre  · 技术社区  · 7 年前

    我在windows和其他软件中制作了一个颤振应用程序,但当我试图编译到iOS时,出现了一个意外错误。在文本字段中,检测到“onTap”不是正确的参数。我不知道发生了什么,在windows中不会返回此错误。无论如何有人知道如何解决这个问题,以及在texfield上检测“onTap”的正确方法是什么吗?

     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,
    

    更新

    我试过了,但没用

     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)));
            },
    

    更新2 :解决方案

    我更新了Flatter和brew。错误消失了。

    0 回复  |  直到 7 年前
        1
  •  10
  •   Kushal Jain    6 年前

    您可以将文本字段包装在 IgnorePointer 小装置。它禁用其子对象上的所有手势。这将使手势检测器工作。

    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)));
            },
    
        2
  •  4
  •   Shubham    4 年前

    TextField已 onTap 像GestureDetector这样的属性使其非常简单。如果你只想 onTap 功能集 readOnly true .

        TextField(
          readOnly: true,
          onTap: () {
            //Your code here
          },
          [...]
        );
    

    与TextFormField类似:

        TextFormField(
          readOnly: true,
          onTap: () {
            //Your code here
          },
          [...]
        );
    
        3
  •  2
  •   Musanza    4 年前

    GestureDetector 不适合我。我用墨水瓶。

    child: InkWell(
                  onTap: () {
                    _selectDate(context);
                  },
                  child: const IgnorePointer(
                    child: TextField(
                      decoration: InputDecoration(
                        labelText: 'Date',
                        hintText: 'Enter Date',
                        border: OutlineInputBorder(),
                        suffixIcon: Icon(Icons.calendar_today_outlined),
                      ),
                    ),
                  ),
                ),
    

    而且效果很好

        4
  •  0
  •   Lay Leangsros    5 年前

    当我使用 墨水池 而不是 手势识别

                    InkWell(
                      child: IgnorePointer(
                        child: TextField(
                        )
                      ),
                     onTap: (){
                    
                     }
                   )
    
        5
  •  -1
  •   Saad Ahmed    4 年前

    文本字段中的点击操作使用只读:false

    TextField(
      readOnly: true,
      onTap: () {
        // open dialogue
      }
    );