Flutter:去除按钮点击时出现的波纹
问题描述
对于习惯iOS的UI风格的开发者来说,初次使用Flutter最令人感觉到不太舒服的就是在点击的时候会出现一个从点击点扩散的一个阴影,类似下图:
解决方案
出现该问题的原因是两个属性引起的,一个是highlightColor
,一个是splashColor
,其中highlightColor
是点击的时候的高亮效果,splashColor
是点击后不松手的扩散效果。
如果想去掉这种波纹效果,可直接把它们设置为Colors.transparent
对于类似RaisedButton这些Widget,可直接设置这些属性,但是,如果每个Widget都要写一遍,那就比较无趣了。
所以一般对于全局的设置,可直接放在theme
里面
new MaterialApp(
title: "Welcome Flutter",
home: new RandomWord(),
theme: new ThemeData(
highlightColor: Colors.transparent,
splashColor: Colors.transparent
),
);