abdalrahman alenzi Asked: 2023-09-02 05:11:19 +0800 CST2023-09-02 05:11:19 +0800 CST 2023-09-02 05:11:19 +0800 CST flutter 中的数字动画 772 在我的 flutter 应用程序中,我有钱包和积分,每当我兑换积分时,我想显示钱包金额增加,如以下视频所示。 对于硬币动画,我已经有一个 Lottie,并且我知道如何实现,但是是否有任何内置包可以用来显示数字的增加? flutter 1 个回答 Voted Best Answer Ashikul Islam Sawan 2023-09-02T06:24:00+08:002023-09-02T06:24:00+08:00 Flutter 团队已经为我们做好了。你的例子就在这里。 class TweenDemo extends StatefulWidget { const TweenDemo({super.key}); @override State<TweenDemo> createState() => _TweenDemoState(); } class _TweenDemoState extends State<TweenDemo> with SingleTickerProviderStateMixin { static const Duration _duration = Duration(seconds: 1); static const double accountBalance = 1000000; late final AnimationController controller; late final Animation<double> animation; @override void initState() { super.initState(); controller = AnimationController(vsync: this, duration: _duration) ..addListener(() { // Marks the widget tree as dirty setState(() {}); }); animation = Tween(begin: 0.0, end: accountBalance).animate(controller); } @override void dispose() { controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Tweens'), ), body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ ConstrainedBox( constraints: const BoxConstraints(maxWidth: 200), child: Text('\$${animation.value.toStringAsFixed(2)}', style: const TextStyle(fontSize: 24)), ), ElevatedButton( child: Text( switch (controller.status) { AnimationStatus.completed => 'Buy a Mansion', AnimationStatus.forward => 'Accruing...', AnimationStatus.reverse => 'Spending...', _ => 'Win the lottery', }, ), onPressed: () { switch (controller.status) { case AnimationStatus.completed: controller.reverse(); default: controller.forward(); } }, ) ], ), ), ); } } 参考:颤动动画
Flutter 团队已经为我们做好了。你的例子就在这里。
参考:颤动动画