点击容器触发onTap()处理程序,但不会显示任何墨水飞溅效果。

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new InkWell(
          onTap: (){print("tapped");},
          child: new Container(
            width: 100.0,
            height: 100.0,
            color: Colors.orange,
          ),
        ),
      ),
    );
  }
}

我试着把InkWell放在容器里,但徒劳。


当前回答

我可以通过使用Stack使我的情况工作。

Stack(
  children: [
    MyCustomWidget(), //              <--- Put this on bottom
    Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: () {},
        child: Ink(
          width: 100,
          height: 100,
        ),
      ),
    ),
  ],
),

本页上的其他答案对我不起作用的原因是我的自定义小部件隐藏了墨水效果,而且我没有一个普通的图像(所以我不能使用ink .image)。

编辑:

你还是可以用墨的。图像,如果您将图像转换为正确的格式。

其他回答

为材质添加透明颜色在我的案例中起作用:

  child: new Material(
    color: Colors.transparent
    child: new InkWell(
      onTap: (){},
      child: new Container(
        width: 100.0,
        height: 100.0,
        color: Colors.amber,
      ),
    ),
  ),

我可以通过使用Stack使我的情况工作。

Stack(
  children: [
    MyCustomWidget(), //              <--- Put this on bottom
    Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: () {},
        child: Ink(
          width: 100,
          height: 100,
        ),
      ),
    ),
  ],
),

本页上的其他答案对我不起作用的原因是我的自定义小部件隐藏了墨水效果,而且我没有一个普通的图像(所以我不能使用ink .image)。

编辑:

你还是可以用墨的。图像,如果您将图像转换为正确的格式。

确保你没有在材质主题中添加以下属性:

(对我来说,这就是问题所在)

splashColor: Colors.transparent
splashFactory: NoSplash.splashFactory

eg:-

MaterialApp(
  home:......,
  theme: ThemeData(
    splashFactory: NoSplash.splashFactory, // Remove this
    splashColor: AppColors.transparent, // Remove this OR Change the color
    ......         
  ),
)

创建一个支持tap的小部件。 将其包装在InkWell小部件中以管理点击回调和波纹 动画。

这是文档中提到的第二点

例子:

InkWell(
        child: TextButton(
          onPressed: () {},
          child: Text('Tapped'),
          ),
        ),
      ),

如果你想在任何小部件上产生涟漪效应,只需:

1-用材料和墨水包装小部件。

2-设置颜色小部件从材料。

3-永远不要为你想让它起波纹的小部件设置颜色。

   Material (
   color: const Color(0xcffFF8906),
   child: InkWell(
   ontap:() { },
   child: Container(
   color: Colors.transparent,
   height: 80,
   width: 80,
 )