InkWell的onTap()未触发

时间:2020-05-16 07:49:10

标签: firebase flutter dart google-cloud-firestore

还尝试了onPressed()IconButton,而不是print。也尝试过IgnorePointer,没有任何变化,有趣的是onLongPress()正在工作。是否是因为在容器内。此绿色按钮正在讨论。

enter image description here

                              Container(
                                  height: 50,
                                  width:50,
                                  padding: const EdgeInsets.all(15.0),
                                  decoration: BoxDecoration(
                                      color: myGreen, shape: BoxShape.circle),
                                  child: InkWell(
                                    child: Icon(
                                      Icons.send,
                                      color: Colors.white,
                                    ),
                                    onTap:(){
                                      print("sdsdsd");
                                      //sendChatToFirestore();
                                    },
                                    onLongPress: (){
                                      print("long press");
                                    },

                                  ),
                                )

2 个答案:

答案 0 :(得分:1)

尝试一下。除了使用多个小部件创建混乱之外,您还可以使用开箱即用的FAB来完成相同的任务

FloatingActionButton(
        onPressed: () {
          print("sdsdsd");
          //sendChatToFirestore();
        },
        backgroundColor: Colors.green,
        child: Icon(
          Icons.send,
          color: Colors.white,
        ),
      ),

或者,如果您想对按钮进行更多控制,请使用简单的FlatButton

FlatButton(               //change to RaisedButton to be raised
          onPressed: () {
            print("sdsdsd");
            //sendChatToFirestore();
          },
          onLongPress: () {
            print("long press");
          },
          padding: EdgeInsets.all(16),
          shape: CircleBorder(),
          color: Colors.green,
          child: Icon(
            Icons.send,
            color: Colors.white,
          ),
        ),

如此简单的小部件无需重新发明轮子

输出

enter image description here

答案 1 :(得分:0)

Material小部件内时,墨水良好的位置会呈现波纹动画。您还可以在此处设置通常会赋予Container的大多数自定义设置。将材料小部件包裹在墨水池中,就完成了。

Container(
  height: 50,
  width:50,
  padding: const EdgeInsets.all(15.0),
  decoration: BoxDecoration(
    color: myGreen, shape: BoxShape.circle),
    child: Material(child:                  // <- This is the magic widget
        InkWell(
          child: Icon(
          Icons.send,
          color: Colors.white,
        ),
     ),
      onTap:(){
          print("sdsdsd");
          //sendChatToFirestore();
      },
      onLongPress: (){
          print("long press");
      },
   ),
)

但是,正如其他答案和评论中所提到的那样,在这种情况下,使用预构建的小部件可能更有意义。当然,除非您需要为小部件设置自己的手势检测系统

相关问题