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


总结
边栏推荐
猜你喜欢

Oracle 数据库基本知识概念

温故知新--常温常新

Custom MVC (imported into jar package) + difference from three-tier architecture + reflection + interview questions

CEC-I 中华学习机使用说明与问答

高清滑环生产过程当中的质量如何把控

Solve the problem that only one line of text is displayed or not displayed in u8glib

MATLAB data type - character type

解决STC8G1K08程序不能运行的问题和端口配置

Moher College -x-forwarded-for injection vulnerability practice

CH423要如何使用,便宜的国产IO扩展芯片
随机推荐
Great vernacular with high concurrency (I)
ESP32实验-自建web服务器配网02
Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)
温故知新--常温常新
memcached基础5
05 | standard design (Part 2): how to standardize the different styles of commit information, which are difficult to read?
Gaussian and Summary Stats
Other service registration and discovery
Simple and fast digital network (network dolls in the network)
ESP32-添加多目录的自定义组件
用代码生成流程图,Markdown的使用方法
Encapsulation of unified result set
剑指 Offer 10- II. 青蛙跳台阶问题
com. fasterxml. jackson. databind. exc.MismatchedInputException: Expected array or string. at [Source:x
这10款文案神器帮你速码,做自媒体还担心写不出文案吗?
2022年地理信息系统与遥感专业就业前景与升学高校排名选择
Is it safe to open a compass account?
Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario
Solve the problem that only one line of text is displayed or not displayed in u8glib
In depth understanding of UDP in the transport layer and the use of UDP in sockets