当前位置:网站首页>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,
),
);
}
}


总结
边栏推荐
- 解决STC8G1K08程序不能运行的问题和端口配置
- 简单快速的数网络(网络中的网络套娃)
- 05 | 規範設計(下):commit 信息風格迥异、難以閱讀,如何規範?
- Simple and fast digital network (network dolls in the network)
- Central Limit Theorem
- At present, which securities company is the best and safest to open an account for stock speculation?
- How to control the quality of HD slip ring in the production process
- Custom jsp[if, foreach, data, select] tag
- 30《MySQL 教程》MySQL 存储引擎概述
- JSON解析,ESP32轻松获取时间气温和天气
猜你喜欢
Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)
超越锂电池——未来电池的概念
Buuctf PWN write UPS (6)
CEC-I 中华学习机使用说明与问答
Solve the problem that only one line of text is displayed or not displayed in u8glib
Redis detailed tutorial
30《MySQL 教程》MySQL 存储引擎概述
05 | 規範設計(下):commit 信息風格迥异、難以閱讀,如何規範?
【Vscode】预览md文件
一键加速索尼相机SD卡文件的复制操作,文件操作批处理教程
随机推荐
Count the logarithm of points that cannot reach each other in an undirected graph [classic adjacency table building +dfs Statistics - > query set optimization] [query set manual / write details]
简单快速的数网络(网络中的网络套娃)
memcached基础1
Operating instructions and Q & A of cec-i China learning machine
These 10 copywriting artifacts help you speed up the code. Are you still worried that you can't write a copywriting for US media?
memcached基础3
buuctf-pwn write-ups (6)
memcached基础5
One click acceleration of Sony camera SD card file copy operation, file operation batch processing tutorial
统一结果集的封装
What are the skills and methods for slip ring installation
Solve the problem that stc8g1k08 program cannot run and port configuration
How to measure the thickness of glass substrate by spectral confocal
根据文件名批量生成文件夹
光谱共焦如何测量玻璃基板厚度
玩转OLED,U8g2动画,增长数字和随机三角形等
Statistical Hypothesis Testing
高清滑环生产过程当中的质量如何把控
Overview of Freescale MCU
2022年地理信息系统与遥感专业就业前景与升学高校排名选择