点击容器触发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放在容器里,但徒劳。
child: Material(
color: Colors.transparent
child: InkWell(
onTap: (){ print("this Ripple!";},
splashColor: Colors.greenAccent,
child: Container(
height:100.0,
color: Colors.white,
),
),
),
在InkWell之前添加材质,并将颜色设置为Colors.transparent。
我已经找到了这个解决方法。我认为它可以帮助你:
Material(
color: Theme.of(context).primaryColor,
child: InkWell(
splashColor: Theme.of(context).primaryColorLight,
child: Container(
height: 100,
),
onTap: () {},
),
)
颜色被赋予材质小部件。它是小部件的默认颜色。
你可以使用Inkwell的splashColor属性来调整波纹效果的颜色。
用简单的话快速解决:
此解决方案适用于小部件树的任何位置。
只需在InkWell之前添加额外的材质,如下所示:
return Container(
.......code.......
),
child: Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () {},
child: Container(
.......code.......
),
),
),
);
参考:
https://api.flutter.dev/flutter/material/InkWell-class.html
“墨水飞溅不可见!”