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

Dart开发:在文本上方叠加Lottie动画(优惠券验证场景)

实现优惠券验证成功时的悬浮Lottie彩屑动画(绝对定位不占空间)

需求:用户输入有效优惠券代码后,展示Lottie彩屑动画,动画需悬浮在屏幕前端,且不占用自身布局空间(类似CSS中position: absolute的效果)。

以下是实现代码:

if (isApplyCouponSuccess)
  Stack(
    children: <Widget>[
      Lottie.asset(
        'assets/images/confetti.json',
        repeat: true,
        fit: BoxFit.fitWidth,
        errorBuilder: (_, __, ___) {
          return const SizedBox();
        },
      ),
      Positioned(
        top: 150,
        left: 0,
        right: 0,
        child: Text(
          couponMsg,
          style: TextStyle(color: Theme.of(context).primaryColor),
          textAlign: TextAlign.center,
        ),
      ),
    ]
  ),

运行效果:
动画效果展示

内容的提问来源于stack exchange,提问作者Hassan Yousuf

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 18:42:40