You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter:如何为带渐变背景的Container添加水波纹效果?

解决带渐变背景的圆形按钮水波纹显示问题

你的问题在于当前用Container实现的渐变背景会覆盖Material组件,导致InkWell的水波纹被遮挡无法显示。要实现渐变背景+水波纹的效果,应该用Ink组件来承载渐变——因为Ink是Flutter Material体系中专门用于绘制在Material表面的组件,水波纹能正确叠加在它上面。

修改后的代码如下:

Material(
  color: Colors.transparent,
  child: Ink(
    height: 64,
    width: 64,
    decoration: const BoxDecoration(
      shape: BoxShape.circle,
      gradient: LinearGradient(
        colors: <Color>[
          Color(0xFF00ABF4),
          Color(0xFF00A1E9),
          Color(0xFF0168AB),
        ],
        begin: Alignment.topCenter,
        end: Alignment.bottomCenter,
      ),
    ),
    child: InkWell(
      onTap: () {},
      splashColor: Colors.green,
      borderRadius: BorderRadius.circular(36),
      child: const Align(
        alignment: Alignment.center,
        child: Icon(
          Icons.add,
          color: Colors.white,
          size: 32,
        ),
      ),
    ),
  ),
)

关键改动说明:

  • 移除原Container,改用Ink组件实现渐变背景,Ink的绘制会与Material的水波纹层融合。
  • 将InkWell作为Ink的子组件,确保水波纹能绘制在渐变背景之上。
  • 用Align组件替代Container的alignment属性居中图标,保持布局效果一致。

调整后,点击按钮就能正常显示绿色水波纹,同时渐变背景也能正确展示。

内容的提问来源于stack exchange,提问作者sm-sayedi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 12:52:05