AnimatedBuilder是用于构建动画的通用小组件。

The Widget's build needs to be called every time the animation's
      // value changes. So add a listener here that will call setState()
      // and trigger the build() method to be called by the framework.
      // If your Widget's build is relatively simple, this is a good option.
      // However, if your build method returns a tree of child Widgets and
      // most of them are not animated you should consider using
      // AnimatedBuilder instead.

相对较为简单的动画组件是 AnimatedWidget。

第一步,创建一个动画,

第二步,通过build方法,将动画装入。

使用预构建的子组件可以提高效率。

视频网址为:https://www.bilibili.com/video/BV1sT4y1J7nr

下面是一个旋转的动画示例

/// Flutter code sample for AnimatedBuilder// This code defines a widget that spins a green square continually. It is
// built with an [AnimatedBuilder] and makes use of the [child] feature to
// avoid having to rebuild the [Container] each time.import 'dart:math' as math;import 'package:flutter/material.dart';void main() => runApp(const MyApp());/// This is the main application widget.
class MyApp extends StatelessWidget {const MyApp({Key? key}) : super(key: key);static const String _title = 'Flutter Code Sample';@overrideWidget build(BuildContext context) {return const MaterialApp(title: _title,home: MyStatefulWidget(),);}
}/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {const MyStatefulWidget({Key? key}) : super(key: key);@overrideState<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}/// This is the private State class that goes with MyStatefulWidget.
/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin.
class _MyStatefulWidgetState extends State<MyStatefulWidget>with TickerProviderStateMixin {late final AnimationController _controller = AnimationController(duration: const Duration(seconds: 10),vsync: this,)..repeat();@overridevoid dispose() {_controller.dispose();super.dispose();}@overrideWidget build(BuildContext context) {return AnimatedBuilder(animation: _controller,child: Container(width: 200.0,height: 200.0,color: Colors.green,child: const Center(child: Text('Whee!'),),),builder: (BuildContext context, Widget? child) {return Transform.rotate(angle: _controller.value * 2.0 * math.pi,child: child,);},);}
}

Flutter 动画设计之AnimatedBuilder相关推荐

  1. Flutter 动画篇

    文章目录 1 概述 2 Animation 3 AnimationController 4 Curve 5 Tween 6 示例 6.1 示例1-ColorTween使用 6.2 示例2-自定义Ani ...

  2. 转:Flutter动画一

    1. 动画介绍 动画对于App来说,非常的重要.很多App,正是因为有了动画,所以才会觉得炫酷.移动端的动画库有非常的多,例如iOS上的Pop.web端的animate.css.Android端的An ...

  3. 学习笔记-Flutter 动画详解(一)

    Flutter 动画详解(一) 本文主要介绍了动画的原理相关概念,对其他平台的动画做了一个简要的梳理,并简要的介绍了Flutter动画的一些知识. 1. 动画介绍 动画对于App来说,非常的重要.很多 ...

  4. flutter 动画展开菜单_Flutter 动画详解(一)

    本文主要介绍了动画的原理相关概念,对其他平台的动画做了一个简要的梳理,并简要的介绍了Flutter动画的一些知识. 1. 动画介绍 动画对于App来说,非常的重要.很多App,正是因为有了动画,所以才 ...

  5. 史上最详细Flutter 动画讲解

    1. 动画介绍 动画对于App来说,非常的重要.很多App,正是因为有了动画,所以才会觉得炫酷.移动端的动画库有非常的多,例如iOS上的Pop.web端的animate.css.Android端的An ...

  6. flutter 点击旋转动画_让动画实现更简单,Flutter 动画简易教程!

    Flutter中的动画功能强大且易于使用.接下来通过一个具体的实例,您将学到关于 Flutter 动画的一切. 难度:中级 今天,我们无法想象移动应用程序里面没有任何动画,当您从一页跳转到另一页时,或 ...

  7. 【flutter 动画汇总】

    Flutter动画一般由这几个部分组成 Animation AnimationController CurvedAnimation Tween1)Animation 是一个范型(T),是一个抽象类,可 ...

  8. Flutter 动画学习

    文章目录 概念理解 插值器/估值器 Flutter中的动画类型 动画 Animation Tween (估值器 给出范围的值) Tween 子类 AnimatedWidget 对于没有附加状态的简单情 ...

  9. Flutter动画(全)

    Flutter动画 一.Flutter Api自带的动画部件. 二.学会图表和动画的结合. 三.结合自定义手势和自定义绘制来搞出各种炫酷的需求. 四.Flare动画 - 一 Flutter Api提供 ...

最新文章

  1. k8s 下线node正确处理姿势
  2. Mybatis-Plus 之 人生中荒废的一下午
  3. 读书笔记之MySQL技术内幕
  4. android music app架构,android-UniversalMusicPlayer 的项目运用
  5. Web 标准实战的评论
  6. Mysql大小写敏感的问题 --转
  7. 如何使用 Java 中执行 Windows 的 CMD 命令
  8. 如何在Hybris Commerce的backoffice里创建扩展字段
  9. c语言实现英文文本编辑器_用flutter实现富文本编辑器(二)
  10. 一行代码引来的安全漏洞,就让我们丢失了整个服务器的控制权
  11. ckrule规则编辑器在wpf中的使用
  12. 目前为止微型计算机,2017年计算机一级考试题库及答案
  13. STC单片机不需要按电源开关下载的方法!
  14. echarts中geoCoordMap世界地图国家及中国城市的经纬度数组整理
  15. 音乐类APP竞品分析报告 酷狗音乐 QQ音乐酷我音乐网易云音乐
  16. 惠普笔记本被政府盖章存隐藏键盘记录器,怎么回事?
  17. 达梦数据库基础知识(七)如何管理表
  18. 【无标题】iTunes更新报错1110错误代码
  19. 软件工程之软件需求分析
  20. Windows10访问共享总是提示输入网络凭证不正确

热门文章

  1. puppet语法和命令详解
  2. 【Puppet】安装配置Puppet
  3. 分布式数据库系统查询优化算法的研究
  4. java疫苗接种预约分配系统springboot+vue
  5. 万能打印机使用的一些小技巧
  6. 验证控件介绍--RegularExpressionValidator
  7. mysql debug test区别_mysql版本区别
  8. 图解 Python 编程(23) | 文件与目录操作(附要点速查表·完结)
  9. Vue学习:事件修饰符
  10. c语言ql,QlExpress使用