【问题标题】:Flutter - InkWell not reacting to onTap inside FlexibleFlutter - InkWell 对灵活内部的 onTap 没有反应
【发布时间】:2019-03-30 12:56:52
【问题描述】:

我想弄清楚为什么我的 InkWell 中的 onTap() 方法不起作用。 InkWell 小部件位于 Flexible 小部件中。这个Flexible 小部件也在里面 Row

这是我的代码:

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

我不知道如何解决我的问题。如果有人能够解决它,那就太棒了XD。

【问题讨论】:

    标签: android ios sqlite dart flutter


    【解决方案1】:

    IgnorePointer 包裹在 Inkwell 的子元素中将解决此问题:

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

    【讨论】:

    • 没问题,谢谢
    • Inkwell 在底部工作表中对我不起作用,但添加它有效。有人可以解释为什么会发生这种情况以及为什么这个解决方案有效吗?
    • 在我的情况下,它在堆栈内不起作用 -> 定位 -> 行 -> 容器......添加忽略指针也没有好处。可能是什么问题?
    • 谢谢!这让我发疯了......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 2020-02-05
    • 2021-10-30
    • 1970-01-01
    • 2017-01-07
    相关资源
    最近更新 更多