假设我有这个小部件:
Card(
child: InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(28.0),
child: RaisedButton(
child: Text('Test'),
onPressed: () {},
),
),
),
),
我仅在轻按Card
时才禁用(防止显示)在InkWell
/ RaisedButton
上的波纹效果,但在轻按Card
时(即在按钮外部)显示)。有什么办法可以达到这种效果?
我认为一般性的问题可能是:当点击内部的InkWell时如何防止周围InkWell的波纹效应?如果您查看源代码,则可以看到RaisedButton
具有Material
和InkWell
会引起波纹的小部件。
您可以处理onHighlightChanged
方法中的逻辑;
Color _color;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Card(
child: InkWell(
splashColor: _color,
highlightColor: _color,
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(28.0),
child: RaisedButton(
onHighlightChanged: (value) {
if (value) {
setState(() => _color = Colors.white);
} else {
Timer(Duration(milliseconds: 200), () {
setState(() => _color = null);
});
}
},
child: Text('Test'),
onPressed: () {},
),
),
),
),
),
);
}