flutter常用内置动画组件
文章目录
PositionedTransition/RelativePositionedTransition
----------------------------------------------------------------
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常用内置动画组件的更多相关文章
- Flutter学习笔记(36)--常用内置动画
如需转载,请注明出处:Flutter学习笔记(36)--常用内置动画 Flutter给我们提供了很多而且很好用的内置动画,这些动画仅仅需要简单的几行代码就可以实现一些不错的效果,Flutter的动画分 ...
- MYSQL常用内置函数详解说明
函数中可以将字段名当作变量来用,变量的值就是该列对应的所有值:在整理98在线字典数据时(http://zidian.98zw.com/),有这要一个需求,想从多音字duoyinzi字段值提取第一个拼音 ...
- request.setCharacterEncoding 和常用内置对象 跳转
1.直接转码 new String(name.getBytes("ISO8859_1"),"GBK") 2. request.setCharactorEncod ...
- JavaScript常用内置对象(window、document、form对象)
由于刚开始学习B/S编程,下面对各种脚本语言有一个宏观的简单认识. 脚本语言(JavaScript,Vbscript,JScript等)介于HTML和C,C++,Java,C#等编程语言之间.它的优势 ...
- ASP.NET常用内置对象
ASP.NET 常用内置对象:Response对象.Request对象.Session对象.Server对象.Application对象 1.Response对象: (1) 用于向浏览器输出信息 常用 ...
- Python常用模块中常用内置函数的具体介绍
Python作为计算机语言中常用的语言,它具有十分强大的功能,但是你知道Python常用模块I的内置模块中常用内置函数都包括哪些具体的函数吗?以下的文章就是对Python常用模块I的内置模块的常用内置 ...
- python字符串常用内置方法
python字符串常用内置方法 定义: 字符串是一个有序的字符的集合,用与存储和表示基本的文本信息. python中引号中间包含的就是字符串. # s1='hello world' # s2=&quo ...
- MySQL学习笔记_7_MySQL常用内置函数
MySQL常用内置函数 说明: 1)可以用在SELECT/UPDATE/DELETE中,及where,orderby,having中 2)在函数里将字段名作为参数,变量的值就是字段所对应的每一行的值. ...
- Tomcat的常用内置对象
Tomcat的常用内置对象 1.request内置对象 所谓内置对象就是容器已经创建好了的对象,如果收到一个用户的请求就会自动创建一个对象来处理客户端发送的一些信息,这个内置对象就是request.类 ...
随机推荐
- 转载:Web安全X-FRAME-OPTIONS 出现两个或多个的原因
转载:https://blog.csdn.net/Teemo_2016/article/details/82051523 在配置文件中配置了 <httpProtocol> < ...
- 5.API详解
Dao 中需要通过 SqlSession 对象来操作 DB.而 SqlSession 对象的创建, 需要其工厂对象 SqlSessionFactory.SqlSessionFactory 对象, 需要 ...
- axios替换jquery的ajax
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script> <scr ...
- react 预览pdf 转换
function getReader(response){ return new Promise(function(resolve,reject){ response.blob().then( blo ...
- 为什么有了uwsgi还要nginx这个“前端”服务器
相信每一个使用nginx+uwsgi+django部署过的人,都感到非常复杂.到底为什么一个项目的发布要经过这么多层级,他们每一层有什么理由存在?这就带大家宏观地看待一下 首先nginx 是对外的服务 ...
- selenium检测webdriver封爬虫的解决方法
有不少朋友在开发爬虫的过程中喜欢使用Selenium + Chromedriver,以为这样就能做到不被网站的反爬虫机制发现. 先不说淘宝这种基于用户行为的反爬虫策略,仅仅是一个普通的小网站,使用一行 ...
- Linux下批量修改文件编码
假设需要将所有afish目录下的php文件,编码从gb2312转到utf8 cd afish find ./ -type f -name “*.php”|while read line;do echo ...
- jQuery超酷响应式瀑布流效果
参考 http://www.sucaihuo.com/js/74.html <script src="scripts/blocksit.min.js"></scr ...
- No provider available from registry出错
dubbo+zookeeper进行分布式远程调用时No provider available from registry出错 查看dubbo服务:http://192.168.0.100:8080/d ...
- redis主从+哨兵 安装配置一
一.目的 实现redis的高可用. 二.同步过程 注意:当Master在后台把数据保存到快照文件完成之后,Master会把这个快照文件传送给Slave,而Slave则把内存清空后,加载该文件到内存中: ...