Flutter之内置动画(转)
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
用于构建动画的通用小部件。用它包裹可以实现根据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不同属性使用动画
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的动画版本,它需要一个特定的动画来将孩子的位置从动画的生命周期的起始位置移到结束位置。
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~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使用缩放动画
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
宽度或者高度缩放
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之内置动画(转)的更多相关文章
- Flutter学习笔记(36)--常用内置动画
如需转载,请注明出处:Flutter学习笔记(36)--常用内置动画 Flutter给我们提供了很多而且很好用的内置动画,这些动画仅仅需要简单的几行代码就可以实现一些不错的效果,Flutter的动画分 ...
- Flutter 中的动画
Flutter 中动画的创建有很多种, 需要根据具体的需求选择不同的动画.如果只是简单的布局等的动画直接使用最简单的隐式动画就可以了,因为隐式动画是由框架控制的,所以仅仅只需要更改变需要变化属性就可以 ...
- 老李分享:持续集成学好jenkins之内置命令
老李分享:持续集成学好jenkins之内置命令 Jenkins命令调用方式:调用Jenkins命令设置job的描述信息. $JAVA_BIN-jar "$JENKINS_CLI_JAR& ...
- zabbix Server 4.0 部署及之内置item使用案例
zabbix Server 4.0 部署及之内置item使用案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.zabbix组件架构概述(图片摘自网络) 1>.zabbi ...
- python设计模式之内置装饰器使用(四)
前言 python内部有许多内建装饰器,它们都有特别的功能,下面对其归纳一下. 系列文章 python设计模式之单例模式(一) python设计模式之常用创建模式总结(二) python设计模式之装饰 ...
- velocity.ui2.0所有的内置动画名称
velocity升级到2.0后api发生了变化,按照原来的名称已经不能调用原来的动画效果,新的名称如下:velocity.ui2.0所有的内置动画名称 bounce flash headShake j ...
- 你知道吗,Flutter内置了10多种Button控件
注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 Flutter内置了10多种Button(按钮)类控件供我 ...
- python进阶之内置方法
python进阶之内置方法 字符串类型的内置方法 常用操作与方法: 按索引取值 str[index] 切片 ste[start:stop:step] 长度 len(str) 成员运算in和not in ...
- 【Flutter 实战】动画序列、共享动画、路由动画
老孟导读:此篇文章是 Flutter 动画系列文章第四篇,本文介绍动画序列.共享动画.路由动画. 动画序列 Flutter中组合动画使用Interval,Interval继承自Curve,用法如下: ...
随机推荐
- springboot~yml里的自定义配置
主要介绍三种,字符串配置,数组配置和带默认值的配置 字符串配置 //yml setString: hello /** * 字符串. */ @Value("${setString}" ...
- node.js学习资料(2015-12)
使用vscode开发,设置代码智能提示的方法,cd 项目目录,然后使用以下命令npm install tsd -gtsd install node express angular -ros 下载 Gi ...
- Nginx反向代理后,java获取客户端真实IP地址
一般情况下,java获取客户端IP地址的方法为request.getRemoteAddr();但这只是在没有网关或者代理的情况下,如果客户端将请求发送到nginx,再由nginx进行反向代理到目标服务 ...
- nginx优化之配置文件优化一常用参数
#定义nginx运行的用户和用户组 user www www; #启动进程,通常设置成和cpu的数量相等 worker_processes 8 ; #为每个进程分配CPU,上面京8个进程分配到 ...
- There was a problem with the instance info replicator
There was a problem with the instance info replicator 错误原因: 该服务尝试将自己作为客服端注册 解决办法: 在application.yml配置 ...
- 告别 hash 路由,迎接 history 路由
博客地址:https://ainyi.com/69 三月来了,春天还会远吗.. 在这里,隆重宣布本博客告别 Vue 传统的 hash 路由,迎接好看而优雅的 history 路由~~ 映照官方说法 v ...
- SpringIOC/DI(2)
2019-03-08/09:24:37 开发环境:IDEA 1.创建Spring项目 File--New--project--Spring--Creat empty Spring-config.xml ...
- Dynamics 365中显示格式为URL的字段极少部分URL值录入了不显示怎么回事?
微软动态CRM专家罗勇 ,回复318或者20190315可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 对于如下类型的字段, ...
- openlayers三:添加图片和图标
openlayers添加图片是指: 添加在地图上的图片会跟随地图同步放大缩小 而添加图标是指: 添加在地图上的图片不会跟随地图同步放大缩小 添加图片: 首先初始化图片图层: initImageLaye ...
- PM过程能力成熟度4级
话说3级的PM已经非常厉害了,但仍然处于定性阶段.如何才能不动声色的跟BOSS过招?PM 4级就是让数字变成你的嘴巴,开启项目管理的量化大门.因此,4级PM的工作重心(详见上一篇文章中的表格),也会逐 ...