Firebase InkWell的onTap()未触发

Firebase InkWell的onTap()未触发,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,还尝试了onPressed()图标按钮,但未打印。尝试忽略指针,没有改变,有趣的是onLongPress()正在工作。这是因为在一个容器中。我说的这个绿色按钮 试试这个。你可以使用开箱即用的FAB来做同样的事情,而不是用多个widget来制造混乱 FloatingActionButton( onPressed: () { print("sdsdsd"); //sendChatToFirestore(); },

还尝试了onPressed()图标按钮,但未打印。尝试忽略指针,没有改变,有趣的是onLongPress()正在工作。这是因为在一个容器中。我说的这个绿色按钮


试试这个。你可以使用开箱即用的FAB来做同样的事情,而不是用多个widget来制造混乱

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,
          ),
        ),
没有必要为这样简单的小部件重新发明轮子

输出


墨水井在
材质
小部件中渲染涟漪动画。您也可以在此处设置通常提供给
容器的大多数自定义设置。用一个材质小部件包住墨水瓶,就完成了

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");
      },
   ),
)
容器(
身高:50,
宽度:50,
填充:常数边集全部(15.0),
装饰:盒子装饰(
颜色:myGreen,形状:BoxShape.circle),

儿童:材料(child://只需使用
Icon
而不是
IconButton
或删除
InkWell
。您得到了两个onPressed和onTap方法,它们基本上是同时触发的。删除其中一个,它将work@Blasanka最初它是图标,但不起作用,所以尝试了图标按钮。@delmin好吧,那就是are两个不同的属性,但是的,我尝试过删除OnLongPress以确保它仍然不起作用。两个不同的属性在同一个手势下被触发…删除onTap或onPressed。你不能在一个小部件中同时拥有这两个属性!!!这也会产生连锁反应吗?而且这也不能回答问题,为什么onTap()没有被触发,是不是dart版本的错误?是的…它给你的效果和普通按钮一样。试试看,让我知道它不是错误。这只是不正确地使用了你这边的小部件和你在问题中的以前的代码,顺便说一句,我已经测试了你的更新代码,并且正确地触发了onTap
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");
      },
   ),
)