当前位置:网站首页>flutter系列之:flutter中的flow
flutter系列之:flutter中的flow
2022-06-27 00:33:00 【InfoQ】
简介
Flow和FlowDelegate
class Flow extends MultiChildRenderObjectWidget
Flow({
Key? key,
required this.delegate,
List<Widget> children = const <Widget>[],
this.clipBehavior = Clip.hardEdge,
}) : assert(delegate != null),
assert(clipBehavior != null),
super(key: key, children: RepaintBoundary.wrapAll(children));
Size getSize(BoxConstraints constraints) => constraints.biggest;
BoxConstraints getConstraintsForChild(int i, BoxConstraints constraints) => constraints;
void paintChildren(FlowPaintingContext context);
bool shouldRelayout(covariant FlowDelegate oldDelegate) => false;
bool shouldRepaint(covariant FlowDelegate oldDelegate);
Flow的应用
final List<IconData> buttonItems = <IconData>[
Icons.home,
Icons.ac_unit,
Icons.adb,
Icons.airplanemode_active,
Icons.account_box_rounded,
];
Widget flowButtonItem(IconData icon) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: IconButton(
icon: Icon(icon,
size: 50,
color: Colors.blue
),
onPressed: () {
buttonAnimation.status == AnimationStatus.completed
? buttonAnimation.reverse()
: buttonAnimation.forward();
},
)
);
}
AnimationController buttonAnimation = AnimationController(
duration: const Duration(milliseconds: 250),
vsync: this,
);
Widget build(BuildContext context) {
return Flow(
delegate: FlowButtonDelegate(buttonAnimation: buttonAnimation),
children:
buttonItems.map<Widget>((IconData icon) => flowButtonItem(icon)).toList(),
);
}
class FlowButtonDelegate extends FlowDelegate {
FlowButtonDelegate({required this.buttonAnimation})
: super(repaint: buttonAnimation);
final Animation<double> buttonAnimation;
@override
bool shouldRepaint(FlowButtonDelegate oldDelegate) {
return buttonAnimation != oldDelegate.buttonAnimation;
}
@override
void paintChildren(FlowPaintingContext context) {
double dy = 0.0;
for (int i = 0; i < context.childCount; ++i) {
dy = context.getChildSize(i)!.height * i;
context.paintChild(
i,
transform: Matrix4.translationValues(
0,
dy * buttonAnimation.value,
0,
),
);
}
}


总结
边栏推荐
- Xiaobai looks at MySQL -- installing MySQL in Windows Environment
- Unable to create a folder to save the sketch: MKDIR sketch
- ESP32-SOLO开发教程,解决CONFIG_FREERTOS_UNICORE问题
- 基于SSMP的宠物医院管理系统
- 小白看MySQL--windows环境安装MySQL
- CH423要如何使用,便宜的国产IO扩展芯片
- LeetCode 142. 环形链表 II
- 2022 Health Expo, Shandong health care exhibition, postpartum health and sleep health exhibition
- 如何把老式键盘转换成USB键盘并且自己编程?
- 滑环安装有哪些技巧和方法
猜你喜欢

Unable to create a folder to save the sketch: MKDIR sketch

自定义MVC(导成jar包)+与三层架构的区别+反射+面试题

Sword finger offer 10- ii Frog jumping on steps

ESP32-添加多目录的自定义组件

About Random Numbers

BootstrapBlazor + FreeSql实战 Chart 图表使用(2)

Implementation of ARP module in LwIP

07 | 工作流设计:如何设计合理的多人开发模式?

简单快速的数网络(网络中的网络套娃)

【Mysql】时间字段默认设置为当前时间
随机推荐
[UVM actual battle== > episode_3] ~ assertion, sequence, property
大健康行业年度必参盛会,2022山东国际大健康产业博览会
MySQL之账号管理、建库以及四大引擎+案例
解决u8glib只显示一行文字或者不显示的问题
Esp32-solo development tutorial to solve config_ FREERTOS_ UNICORE problem
Implementation of ARP module in LwIP
07 | 工作流设计:如何设计合理的多人开发模式?
Special topic II on mathematical physics of the sprint strong foundation program
目前哪个证券公司炒股开户是最好最安全的?
Oracle database basics concepts
How to use ch423? Cheap domestic IO expansion chip
The [MySQL] time field is set to the current time by default
数据库面试题+sql语句解析
Statistical Hypothesis Testing
Network in network (dolls)
从位图到布隆过滤器,C#实现
memcached基础1
滑环安装有哪些技巧和方法
解决unable to create a folder to save the sketch: mkdir sketch
记录一次换行符引起的bug