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
相关产品推荐
相关产品推荐

