文章目录

AnimatedContainer

AnimatedCrossFade

Hero

AnimatedBuilder

DecoratedBoxTransition

FadeTransition

PositionedTransition/RelativePositionedTransition

RotationTransition

ScaleTransition

AlignTransition

SizeTransition

SlideTransition

AnimatedDefaultTextStyle

AnimatedListState

AnimatedModalBarrier

AnimatedOpacity

AnimatedPhysicalModel

AnimatedPositioned

AnimatedSize

AnimatedWidget

AnimatedWidgetBaseState

----------------------------------------------------------------

AnimatedContainer

属性改变, 根据设定的时间过渡大小颜色位移等, 类似transition

属性变化的动画

GestureDetector(
onTap: () {
setState(() {
widget.width = 100.0;
});
},
child: AnimatedContainer(
duration: Duration(seconds: 2),
width: widget.width,
height: 200.0,
color: Colors.red,
child: Text('test'),
padding: EdgeInsets.only(bottom: 100.0),
curve: Curves.bounceOut,
),
)

  

AnimatedCrossFade

一个widget,在两个孩子之间交叉淡入,并同时调整他们的尺寸, firstChild 在一定时间逐渐变成 secondChild

整个元素变化的动画

AnimatedCrossFade(
firstChild: Container(
width: 100.0,
height: 100.0,
color: Colors.green,
child: Text('123'),
),
secondChild: Container(
width: 200.0,
height: 100.0,
color: Colors.red,
child: Text('456'),
),
crossFadeState: widget.first ? CrossFadeState.showFirst : CrossFadeState.showSecond,
duration: Duration(seconds: 2)
)

  

Hero

https://flutterchina.club/animations/hero-animations/

AnimatedBuilder

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

用它包裹可以实现根据animation变化而变化的动画

AnimatedBuilder(
animation: animation2,
builder: (BuildContext ctx, Widget child) {
return Container(
transform:
Matrix4.translationValues(0, animation2.value, 0),
alignment: Alignment.topLeft,
padding: EdgeInsets.fromLTRB(40.0, 30.0, 40.0, 0.0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.topLeft,
child: Text(
'我是标题',
style: TextStyle(fontSize: 18.0),
),
),
Container(
padding: EdgeInsets.only(top: 10.0),
alignment: Alignment.topLeft,
child: Text('我是内容啦啦啦啦'),
)
],
),
);
},
)

  

DecoratedBoxTransition

DecoratedBox的动画版本,可以给它的Decoration不同属性使用动画

针对Decoration的属性变化的动画

Animation<Decoration> animationTest;
AnimationController controllerTest; controllerTest = new AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this); animationTest = DecorationTween(
begin: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(0.0)),
color: Colors.red
),
end: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
color: Colors.green
)
).animate(controllerTest); DecoratedBoxTransition(
decoration: animationTest,
child: Container(
width: 100.0,
height: 100.0,
)
)

  

FadeTransition

对透明度使用动画的widget

透明度的包装动画, 比直接用Opacity封装简单, 不如AnimatedOpacity方便

Animation<double> animationTest;
AnimationController controllerTest; controllerTest = new AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animationTest = new Tween(begin: 1.0, end: 0.0).animate(controllerTest); FadeTransition(
opacity: animationTest,
child: Container(
width: 100.0,
height: 100.0,
decoration: BoxDecoration(
color: Colors.red,
border: Border.all(color: Colors.green, width: 10.0),
borderRadius: BorderRadius.all(Radius.circular(20.0)),
),
)
)

  

PositionedTransition/RelativePositionedTransition

Positioned的动画版本,它需要一个特定的动画来将孩子的位置从动画的生命周期的起始位置移到结束位置。

绝对定位的动画实现, 需要Stack包裹

Animation<RelativeRect> animationTest;
AnimationController controllerTest; controllerTest = new AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this); animationTest = RelativeRectTween(
begin: RelativeRect.fromLTRB(200.0, 200.0, 200.0, 200.0),
end: RelativeRect.fromLTRB(20.0, 20.0, 20.0, 20.0))
.animate(controllerTest); Stack(children: <Widget>[
PositionedTransition(
rect: animationTest,
child: GestureDetector(
onTap: () {
controllerTest.forward();
},
child: Container(
width: 100.0,
height: 100.0,
color: Colors.red,
),
),
)
]),

  

RotationTransition

对widget使用旋转动画

1.0 = 360度

RotationTransition(
turns: new Tween(begin: 0.0, end: 0.5).animate(controllerTest),
child: Container(
width: 100.0,
height: 100.0,
color: Colors.red,
child: Text('12345678'),
)
)

  

ScaleTransition

对widget使用缩放动画

1.0为初始

ScaleTransition(
scale: new Tween(begin: 1.0, end: 0.5).animate(controllerTest),
child: Container(
width: 100.0,
height: 100.0,
color: Colors.red,
child: Text('12345678'),
)
)

  

AlignTransition

挪到中间

SizeTransition

宽度或者高度缩放

重点是axis控制的, 百叶窗效果可实现

SizeTransition(
axis: Axis.horizontal, //控制宽度或者高度缩放
sizeFactor:
new Tween(begin: 1.0, end: 0.5).animate(controllerTest),
child: Container(
width: 100.0,
height: 100.0,
color: Colors.red,
child: Text('12345678'),
)
)

  

SlideTransition

对相对于其正常位置的某个位置之间使用动画

Offset是相对于自己移动的百分比

SlideTransition(
position: new Tween(
begin: Offset(0.0, 0.0),
end: Offset(0.5, 0.3),
).animate(controllerTest),
child: Container(
width: 100.0,
height: 100.0,
color: Colors.red,
child: Text('12345678'),
)
)

  

AnimatedDefaultTextStyle

在文本样式切换时使用动画

AnimatedDefaultTextStyle(child: Text('1234567'), style: TextStyle(
color: widget.color
), duration: Duration(seconds: 2)
)

  

AnimatedListState

动画列表的state

AnimatedListdemo用

AnimatedModalBarrier

一个阻止用户与widget交互的widget

AnimatedOpacity
Opacity的动画版本,在给定的透明度变化时,自动地在给定的一段时间内改变孩子的Opacity

AnimatedOpacity(
opacity: widget.opacity,
duration: Duration(seconds: 2),
child: Container(
width: 100.0,
height: 100.0,
color: Colors.black,
)
)

  

AnimatedPhysicalModel

PhysicalModel的动画版本

阴影动画

AnimatedPhysicalModel(
duration: Duration(seconds: 2),
shape: BoxShape.rectangle,
elevation: 20.0,
color: Colors.transparent,
shadowColor: widget.color,
child: Container(
width: 100.0,
height: 100.0,
color: Colors.black,
)
)

  

AnimatedPositioned

动画版本的Positioned,每当给定位置的变化,自动在给定的时间内转换孩子的位置。

相对于PositionedTransition简单一些, 但是功能相对单一

Stack(children: <Widget>[
AnimatedPositioned(
width: widget.width,
duration: Duration(seconds: 2),
child: GestureDetector(
onTap: (){ setState(() {
widget.width = 100.0;
});
},
child: Container(
width: 100.0,
height: 100.0,
color: Colors.red,
),
)
)
]),

  

AnimatedSize

动画widget,当给定的孩子的大小变化时,它自动地在给定时间内转换它的大小。

AnimatedWidget

当给定的Listenable改变值时,会重新构建该widget

AnimatedWidgetBaseState

具有隐式动画的widget的基类

原文地址: https://blog.csdn.net/weixin_43929882/article/details/88531433

flutter常用内置动画组件的更多相关文章

  1. Flutter学习笔记(36)--常用内置动画

    如需转载,请注明出处:Flutter学习笔记(36)--常用内置动画 Flutter给我们提供了很多而且很好用的内置动画,这些动画仅仅需要简单的几行代码就可以实现一些不错的效果,Flutter的动画分 ...

  2. MYSQL常用内置函数详解说明

    函数中可以将字段名当作变量来用,变量的值就是该列对应的所有值:在整理98在线字典数据时(http://zidian.98zw.com/),有这要一个需求,想从多音字duoyinzi字段值提取第一个拼音 ...

  3. request.setCharacterEncoding 和常用内置对象 跳转

    1.直接转码 new String(name.getBytes("ISO8859_1"),"GBK") 2. request.setCharactorEncod ...

  4. JavaScript常用内置对象(window、document、form对象)

    由于刚开始学习B/S编程,下面对各种脚本语言有一个宏观的简单认识. 脚本语言(JavaScript,Vbscript,JScript等)介于HTML和C,C++,Java,C#等编程语言之间.它的优势 ...

  5. ASP.NET常用内置对象

    ASP.NET 常用内置对象:Response对象.Request对象.Session对象.Server对象.Application对象 1.Response对象: (1) 用于向浏览器输出信息 常用 ...

  6. Python常用模块中常用内置函数的具体介绍

    Python作为计算机语言中常用的语言,它具有十分强大的功能,但是你知道Python常用模块I的内置模块中常用内置函数都包括哪些具体的函数吗?以下的文章就是对Python常用模块I的内置模块的常用内置 ...

  7. python字符串常用内置方法

    python字符串常用内置方法 定义: 字符串是一个有序的字符的集合,用与存储和表示基本的文本信息. python中引号中间包含的就是字符串. # s1='hello world' # s2=&quo ...

  8. MySQL学习笔记_7_MySQL常用内置函数

    MySQL常用内置函数 说明: 1)可以用在SELECT/UPDATE/DELETE中,及where,orderby,having中 2)在函数里将字段名作为参数,变量的值就是字段所对应的每一行的值. ...

  9. Tomcat的常用内置对象

    Tomcat的常用内置对象 1.request内置对象 所谓内置对象就是容器已经创建好了的对象,如果收到一个用户的请求就会自动创建一个对象来处理客户端发送的一些信息,这个内置对象就是request.类 ...

随机推荐

  1. queryURLParams

    let url = 'http://www.douqu.com/index.html?name1=val1&name2=val2'; //1.提取问号后的字符 let asktext = ur ...

  2. angular-file-upload.min.js.map文件下载

    https://github.com/nervgh/angular-file-upload 下载地址 在文件 菜单栏有对应文件

  3. MYSQL AND 和 OR

    AND 和 OR     如果你失忆了,希望你能想起曾经为了追求梦想的你.    QQ群:651080565(php/web 学习课堂)   我们查询数据的时候,会使用条件来过滤数据,达到筛选效果,过 ...

  4. wamp集成环境安装redis

    1.你先下载好Windows平台的redis 地址:https://github.com/MicrosoftArchive/redis/releases 我下载的是5.8M的那个 2.下载对应版本的p ...

  5. Python学习记录6-list、tuple、dict、set复习

    数据类型在一门语言中是非常重要的,所以选择再次学习一下加深记忆.本次主要参考了大神廖雪峰的官方网站,非常感谢大神,讲的很清晰,收获很大. 标准数据类型 Number(数字) String(字符串) L ...

  6. 关于rtos中任务切换时的程序流程

    今天和一个小伙伴讨论了一下基于cortex-m3内核的RTOS在任务切换时的程序流程,小伙伴说国内某搜索引擎都搜不到这类的信息,所以我才打算写下来,硬件平台是stm32f1​. 这里的切换有两种情况: ...

  7. (3)你的第一个python程序

    Life is short,you need python!人生苦短,你需要python!好吧,干了这碗鸡汤................. hello world 没错,几乎是所有程序猿的第一个程 ...

  8. vue.js中父组件触发子组件中的方法

    知识点:vue.js中,父组件的method中,触发子组件中的方法,获得子组件中的定义的属性 (1)子组件 : child_crud.js var html_child_crud= "< ...

  9. golang map多层嵌套使用及遍历方法汇总

    原文:https://blog.csdn.net/boyhandsome7/article/details/79734847 ------------------------------------- ...

  10. iphone bandwidth

    iPhone 8, 8 Plus, X peak throughput of ~24GBs iPhone XS, XS Max, XR peak throughput of ~34GBs 在iphon ...