当前位置:网站首页>Come after me! Flutter realizes chasing animation
Come after me! Flutter realizes chasing animation
2022-07-20 21:26:00 【InfoQ】
Stack
Positioned
Stack
Positioned
top
bottom
height
left
right
width
AnimatedPositioned
Stack
AnimatedPositioned

Effect analysis
- Along the great circle 4 Point movement effect , We can control the starting position of the ball and we can do it .
- The bounce effect can be used
bounceIn
Curve realization .
- The effect of chasing one after another , You can set an ordered array of positions , The position of one ball is the next position of another ball , This can be achieved by taking positions from the position array using different subscripts .
- Realization of repetitive dynamic effect : Repeated dynamic use
AnimatedPositioned
OfonEnd
Trigger , Call... At the end of each timesetState
Add the subscript of the control position 1, You can achieve the effect of animation cycle .
Code implementation
class _AnimatedPositionedDemoState extends State<AnimatedPositionedDemo> {
final roundSize = 200.0;
var ballSize = 50.0;
late List<Offset> animatedOffsets;
int index = 0;
@override
void initState() {
animatedOffsets = [
Offset(0.0, (roundSize - ballSize) / 2),
Offset((roundSize - ballSize) / 2, roundSize - ballSize),
Offset(roundSize - ballSize, (roundSize - ballSize) / 2),
Offset((roundSize - ballSize) / 2, 0.0),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AnimatedPositioned'),
brightness: Brightness.dark,
backgroundColor: Colors.black,
),
backgroundColor: Colors.black,
body: Center(
child: Stack(children: [
ClipOval(
child: Container(
width: roundSize,
height: roundSize,
color: Colors.white,
),
),
AnimatedPositioned(
top: animatedOffsets[index].dy,
height: ballSize,
left: animatedOffsets[index].dx,
width: ballSize,
child: ClipOval(
child: Container(
color: Colors.blue,
),
),
duration: Duration(seconds: 2),
curve: Curves.bounceIn,
onEnd: () {
setState(() {
index = (index + 1) % animatedOffsets.length;
});
},
),
AnimatedPositioned(
top: animatedOffsets[(index + 1) % animatedOffsets.length].dy,
height: ballSize,
left: animatedOffsets[(index + 1) % animatedOffsets.length].dx,
width: ballSize,
child: ClipOval(
child: Container(
color: Colors.orange,
),
),
duration: Duration(seconds: 2),
curve: Curves.bounceIn,
),
]),
),
floatingActionButton: FloatingActionButton(
child: Text(
' Walk you ',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
),
onPressed: () {
setState(() {
index = (index + 1) % 4;
});
},
),
);
}
}
AnimatedPositioned(
top: animatedOffsets[index].dy,
height: ballSize,
left: animatedOffsets[index].dx,
width: ballSize,
child: ClipOval(
child: Container(
color: Colors.blue,
),
),
duration: Duration(seconds: 2),
curve: Curves.bounceIn,
onEnd: () {
setState(() {
index = (index + 1) % animatedOffsets.length;
});
},
),
left
top
onEnd
setState
Changing play

summary
AnimatedPositioned
Flutter
loading

边栏推荐
- 迅速学tar命令对文件的打包压缩与解压缩
- Introduction and use cases of iterator
- IMPALA2.12环境安装
- 迭代器(iterator)的简介及使用案例
- 实现统一账号登录,sonarqube集成ldap
- Array of daily questions for Niuke
- ECCV 2022 | Kuangshi proposed a semi supervised target detection model, dense teacher, which achieved SOTA performance
- 最受IT公司欢迎的 30 款开源软件
- Ajout, suppression, modification et exception de cookies
- Redis 很屌,不懂使用规范就糟蹋了
猜你喜欢
[development tutorial 5] crazy shell arm function mobile phone serial port experiment tutorial
leetcode 面试题 05.06. 整数转换
Skywalking全链路监控集群和动态部署
STM32 HAL库串口同时收发,接收卡死?
Array of daily questions for Niuke
Redis 实战篇:巧用 Bitmap 实现亿级海量数据统计
【golang从入门到实践】石头剪刀布游戏
你来追我呀!Flutter 实现追逐动画
SAP MM 事务代码MIGO 移动类型 561保存后报错-document number ### was already assigned
服务器内网与外网的四大区别?
随机推荐
Redis 很屌,不懂使用规范就糟蹋了
Blueprint class view method
Redis high availability: you call this sentinel sentinel cluster principle
Redis 核心篇:唯快不破的秘密
Unity3D学习笔记9——加载纹理
Project knowledge points
Unity3d learning note 9 - loading textures
突发!英国指控华为设备存在重大缺陷(附报告)
LVGL 8.2 Tabview
R语言使用ggpubr包的gghistogram函数可视化分组箱图、添加分组均值、自定义分组色彩、添加轴须图(rug)、添加密度曲线、添加双y轴分别表示频率以及密度曲线的密度值
最受IT公司欢迎的 30 款开源软件
Redis is awesome. If you don't understand the usage specification, it will be ruined
项目知识点
Part of the second Shanxi Network Security Skills Competition (Enterprise Group) WP (VI)
报告解读下载 | 墨天轮七月数据库行业报告,居安思危,安全先行
What is dbc2000? Dbc2000 database file details
Face contour image extraction in online conference (III) -- feature extraction of face contour image in Dlib database
Win10+libtorch+yolov5-6.0 deployment
索尼宣布关闭北京手机工厂!产线将迁至泰国,成本可降低一半!
The R language uses the gghistogram function of ggpubr package to visualize the grouping box diagram, add the grouping mean value, customize the grouping color, add the axial whisker diagram (rug), ad