Flutter Material3中如何创建带阴影的纯白ElevatedButton?
当给ElevatedButton设置elevation后,按钮实际颜色会偏离设置的backgroundColor,这是因为Material Design默认会给带阴影的组件叠加一层surface tint颜色以强化层级感知,导致你的纯白按钮看起来偏暗。
只需在ButtonStyle中添加surfaceTintColor: MaterialStateProperty.all(Colors.transparent),就能让按钮完全显示你设置的纯白背景:
ButtonStyle( elevation: MaterialStateProperty.all(5), backgroundColor: MaterialStateProperty.all(Colors.white), surfaceTintColor: MaterialStateProperty.all(Colors.transparent), // 关键代码 )
这个方法适用于所有需要精确控制带elevation的ElevatedButton颜色的场景,将surfaceTintColor设为透明后,backgroundColor就能完全展示,不会被默认的色调叠加影响。
内容的提问来源于stack exchange,提问作者SpeeDfire12
相关产品推荐
相关产品推荐

