当前位置:网站首页>Flutter Widget : Flow
Flutter Widget : Flow
2022-07-03 12:05:00 【J_ D_ Chi】
Write it at the front
\Flow Components need to be matched \FlowDelegate Use , stay \FlowDelegate Write logic in ,\Flow You can adjust its children Size and location of .
Use \Flow Is used to optimize children Use transformation matrix (transformation matrices) Rearrange . Be similar to Stack.
That is, when we want to customize a pair children Layout Widget When , have access to \Flow.
Content
Basic usage
From the official example, a basic usage . In this case , In addition to showing the right children Layout , It also demonstrates how to use Animation To make the children The transformation matrix used changes , So as to achieve the change of position .
class FlowMenu extends StatefulWidget {
const FlowMenu({Key? key}) : super(key: key);
@override
_FlowMenuState createState() => _FlowMenuState();
}
class _FlowMenuState extends State<FlowMenu> with SingleTickerProviderStateMixin {
late AnimationController menuAnimation;
IconData lastTapped = Icons.notifications;
final List<IconData> menuItems = <IconData>[
Icons.home,
Icons.new_releases,
Icons.notifications,
Icons.settings,
Icons.menu,
];
void _updateMenu(IconData icon) {
if (icon != Icons.menu) {
setState(() => lastTapped = icon);
}
}
@override
void initState() {
super.initState();
menuAnimation = AnimationController(
duration: const Duration(milliseconds: 250),
vsync: this,
);
}
Widget flowMenuItem(IconData icon) {
final double buttonDiameter = MediaQuery.of(context).size.width / menuItems.length;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: RawMaterialButton(
fillColor: lastTapped == icon ? Colors.amber[700] : Colors.blue,
splashColor: Colors.amber[100],
shape: const CircleBorder(),
constraints: BoxConstraints.tight(Size(buttonDiameter, buttonDiameter)),
onPressed: () {
_updateMenu(icon);
menuAnimation.status == AnimationStatus.completed
? menuAnimation.reverse()
: menuAnimation.forward();
},
child: Icon(
icon,
color: Colors.white,
size: 45.0,
),
),
);
}
@override
Widget build(BuildContext context) {
return Flow(
delegate: FlowMenuDelegate(menuAnimation: menuAnimation),
children: menuItems.map<Widget>((IconData icon) => flowMenuItem(icon)).toList(),
);
}
}
class FlowMenuDelegate extends FlowDelegate {
FlowMenuDelegate({required this.menuAnimation}) : super(repaint: menuAnimation);
final Animation<double> menuAnimation;
@override
bool shouldRepaint(FlowMenuDelegate oldDelegate) {
return menuAnimation != oldDelegate.menuAnimation;
}
@override
void paintChildren(FlowPaintingContext context) {
double dx = 0.0;
for (int i = 0; i < context.childCount; ++i) {
dx = context.getChildSize(i)!.width * i;
context.paintChild(
i,
transform: Matrix4.translationValues(
dx * menuAnimation.value,
0,
0,
),
);
}
}
}
Compared to the layout Stage layout children, Here it is. paint Stage , stay \FlowDelegate.paintChildren In the method , Give Way children Use the transformation matrix to determine the position . This is done simply by \Flow Redraw , So as to achieve children Efficient relocation . There is no need to let children Then rearrange .
Most effectively promote \Flow The way to redraw is to \FlowDelegate The construction method of provides a Animation, such \Flow Will monitor this Animation, Then when Animation When there is a callback ,\Flow Will redraw , Avoided build and layout.
Construction method
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));
Flow.unwrapped({
Key? key,
required this.delegate,
List<Widget> children = const <Widget>[],
this.clipBehavior = Clip.hardEdge,
}) : assert(delegate != null),
assert(clipBehavior != null),
super(key: key, children: children);
...
}
\Flow There are two constructors , The difference is that by default RepaintBoundary Package , It wraps every children, Avoid when \Flow When redrawing , Lead to children Also redrawn .
边栏推荐
猜你喜欢

vulnhub之raven2

Niuniu's team competition

During FTP login, the error "530 login incorrect.login failed" is reported

错排问题 (抽奖,发邮件)
![[official MySQL document] deadlock](/img/2d/04e97d696f20c2524701888ea9cd10.png)
[official MySQL document] deadlock

After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good

The tutor put forward 20 pieces of advice to help graduate students successfully complete their studies: first, don't plan to take a vacation

《剑指offer 03》数组中重复的数字

Unicode encoding table download

Raven2 of vulnhub
随机推荐
Unity3d learning notes 5 - create sub mesh
[MySQL special] read lock and write lock
(数据库提权——Redis)Redis未授权访问漏洞总结
DEJA_VU3D - Cesium功能集 之 053-地下模式效果
优化接口性能
Flutter: about monitoring on flutter applications
Socket TCP for network communication (I)
Cacti监控Redis实现过程
Vulnhub's Nagini
ArcGIS application (XXI) ArcMap method of deleting layer specified features
Hongmeng fourth training
Groovy测试类 和 Junit测试
XML (DTD, XML parsing, XML modeling)
typeScript
Qt OpenGL相机的使用
STL Tutorial 9 deep copy and shallow copy of container elements
QT OpenGL rotate, pan, zoom
PHP導出word方法(一mht)
vulnhub之tomato(西红柿)
Solve msvcp120d DLL and msvcr120d DLL missing