Flutter开发——动画封装类AnimatedBuilder

在Flutter项目中,AnimatedBuilder可以帮助我们减少重复代码,实现动画与组件的解耦。文章通过一个Logo放大-缩小的无限循环动画例子,展示了如何使用AnimatedBuilder,以及其与AnimatedWidget、AnimationController和Tween的配合使用。此外,还提到Flutter提供了许多基于AnimatedBuilder的内置动画类。

在实际项目中,往往会有很多个动画集于一个界面,这时候如果每个界面都实现一遍动画,会出现很多重复代码。那么,Animatedbuilder就可以解决此类问题了。

  • AnimatedBuilder类继承AnimatedWidget类,所以它可以直接作为一个组件来使用。
  • AnimatedBuilder不需要知道如何渲染组件的,也不需要知道如何管理动画对象,只需调用build。
    使用AnimatedBuilder来实现Logo放大–>缩小无限循环的动画。代码如下:
import 'package:flutter/material.dart';

class AnimatedBuilderPage extends StatefulWidget {
   
   
  final String title;
  const AnimatedBuilderPage({
   
   Key? key, required this.title}) : super(key: key);

  
  State<AnimatedBuilderPage> createState() => _AnimatedBuilderPageState();
}

class _AnimatedBuilderPageState extends State<AnimatedBuilderPage>
    with SingleTickerProviderStateMixin {
   
   
  Animation<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值