Flutter 动画集
简化的Flutter交错动画。通过动画配置的形式驱动Flutter交错动画。您可以
- 使用现有的
Flutter Animation Set动画小部件 - 使用
Flutter Animation Set创建新的动画小部件 - 贡献您的Flutter动画集小部件
- 在示例中观看Flutter的所有
曲线
? 安装
dependencies:
flutter_animation_set: ^0.0.4
⚡ 使用动画集小部件
1、导入
import 'package:flutter_animation_set/widget/transition_animations.dart';
import 'package:flutter_animation_set/widget/behavior_animations.dart';
2、使用
child: YYRotatingPlane(),
3、路线图
过渡动画
YYRotatingPlane ✅ |
YYDoubleBounce ✅ |
YYWave ✅ |
YYWanderingCubes ✅ |
YYFadingFour ✅ |
YYFadingCube ✅ |
YYPulse ✅ |
YYThreeBounce ✅ |
YYThreeLine ✅ |
YYCubeGrid ✅ |
YYRotatingCircle ✅ |
YYPumpingHeart ✅ |
YYRipple ✅ |
YYRotateLine ✅ |
YYCubeFadeIn ✅ |
YYBlinkGrid ✅ |
行为动画
YYFadeButton ✅ |
YYSingleLike ✅ |
YYLove ✅ |
YYSpringMenu ✅ |
YYFoldMenu ✅ |
4、致谢
⚡ 自己创建动画集小部件
1、导入
import 'package:flutter_animation_set/animation_set.dart';
import 'package:flutter_animation_set/animator.dart';
2、使用小部件
AnimatorSet(
child: widget.child,
animatorSet: [],
animationType: AnimationType.reverse,
debug: false,
)
AnimatorSet 支持的属性
| 属性 | 含义 | 默认值 |
|---|---|---|
| child | 执行动画的组件 | 不具有 |
| animatorSet | 动画集合 | 不具有 |
| animationType | 控制动画执行的类型 | AnimationType.repeat |
| debug | 输出日志 | 假 |
animationType 的属性
| 属性 | 含义 |
|---|---|
| repeat | 重复动画 |
| reverse | 倒放动画 |
| once | 一次性播放动画 |
3、使用 AnimatorSet API
关于动画小部件
| Widget | 含义 | 描述 |
|---|---|---|
| W | width | 控制宽度变化。如果进行缩放,建议使用 SX |
| H | 高度 | 控制高度变化。如果进行缩放,建议使用 SY |
| P | padding | 控制填充变化 |
| O | opacity | 控制不透明度变化 |
| SX | scaleX | 以中心点缩放 X 轴 |
| SY | scaleY | 以中心点缩放 Y 轴 |
| RX | rotateX | 以中心点围绕 X 轴旋转 |
| RY | rotateY | 以中心点围绕 Y 轴旋转 |
| RZ | rotateZ | 以中心点围绕 Z 轴旋转 |
| TX | transitionX | 以中心点平移 Z 轴 |
| TY | transitionY | 以中心点平移 Y 轴 |
| C | color | 控制背景颜色变化 |
| B | border | 控制背景边框变化 |
关于支持的小部件
| Widget | 含义 | 描述 |
|---|---|---|
| 延迟 | delay timeLine | 延迟时间线以等待 |
| 顺序 | 组合动画 | 通过动画组合,实现同时播放的效果 |
⚡ 示例
1、创建时间线
- 图示显示动画的核心组件是根据时间线制作的
- 在执行过程中,同时有 6 个动画,总动画时长为 900ms
- 使用 ScaleY 组件进行放大和缩小,以便每个矩形都具有波浪效果
- 使用 Delay 组件拖动时间线,以达到 900ms 的动画时长
2、构建 animatorSet
根据上图组装我们的动画组件,它具有以下属性
- from:动画初始值
- to:动画结束值
- duration:动画时长
- delay:动画实际执行的延迟
- curve:动画插值器
animatorSet: [
Delay(duration: before),
SY(from: 0.8, to: 1.6, duration: 200, delay: 0, curve: Curves.linear),
SY(from: 1.6, to: 0.8, duration: 200, delay: 0, curve: Curves.linear),
Delay(duration: after),
],
动画执行的对象是 Container 矩形
Widget makeWave(int before, int after) {
return AnimatorSet(
child: Container(
color: Colors.white,
width: 5,
height: 15,
),
animatorSet: [
Delay(duration: before),
SY(from: 0.8, to: 1.6, duration: 200, delay: 0, curve: Curves.linear),
SY(from: 1.6, to: 0.8, duration: 200, delay: 0, curve: Curves.linear),
Delay(duration: after),
],
);
}
3、转换为代码
class YYWave extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 40,
height: 40,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
makeWave(0, 500),
makeWave(100, 400),
makeWave(200, 300),
makeWave(300, 200),
makeWave(400, 100),
makeWave(500, 0),
],
),
);
}
}
4、完成
更多
1、动画组合
缩放效果需要同时缩放 X 轴和 Y 轴,使用 Serial Widget
animatorSet: [
Serial(
duration: 2000,
serialList: [
SX(from: 0.0, to: 1.0, curve: Curves.easeInOut),
SY(from: 0.0, to: 1.0, curve: Curves.easeInOut),
O(from: 0.5, to: 0.0, delay: 1000, curve: Curves.easeInOut),
],
),
],
完成
2、延时动画
在实际进行动画时处理 delay 属性
class YYThreeLine extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 40,
height: 40,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
makeLine(0),
makeLine(50),
makeLine(100),
],
),
);
}
}
Widget makeLine(int delay) {
return AnimatorSet(
child: Container(
color: Colors.white,
width: 10,
height: 5,
),
animatorSet: [
TY(from: 0.0, to: 5.0, duration: 400, delay: delay, curve: Curves.fastOutSlowIn,),
TY(from: 5.0, to: 0.0, duration: 400, curve: Curves.fastOutSlowIn,),
],
);
}
完成
3、倒放动画
动画播放完成后,通过 animationType 属性设置 animationtype.reverse,使动画倒放
class YYFoldMenu extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 40,
height: 40,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
makeFoldMenu(0, 40),
makeFoldMenu(100, 26.0),
makeFoldMenu(200, 12.0),
],
),
);
}
}
Widget makeFoldMenu(int delay, double toY) {
return AnimatorSet(
animationType: AnimationType.reverse,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
),
width: 30,
height: 10,
),
animatorSet: [
Serial(
duration: 2000,
delay: delay,
serialList: [
TY(from: 0.0, to: toY, curve: Curves.elasticInOut),
SX(from: 1.0, to: 0.1, curve: Curves.elasticInOut),
SY(from: 1.0, to: 0.1, curve: Curves.elasticInOut),
],
),
],
);
}
完成