默认情况下,许多Flutter Material Design小部件在被选中时都会显示飞溅效果。
这适用于IconButton,InkWell,ListTile 和许多其他小工具。
如果您正在创建一个完全自定义的设计,并希望在整个应用程序中禁用这一点,您所需要做的就是这个。
MaterialApp(
theme: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
),
)
或者,你可以通过插入一个父级Theme widget,将其应用于某个widget子树。
Theme(
data: Theme.of(context).copyWith(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
)
child: child,
)
你也可以直接为特定的小组件禁用这个功能。
IconButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
icon: someIcon,
onPressed: someCallback,
)
简单-容易,就像它应该是这样。😎
编码愉快!