当前位置:网站首页>Wrap in shutter
Wrap in shutter
2022-07-18 03:32:00 【A floating boat】
We are flutter Can contain multiple child Of widget When , We often encounter situations beyond the boundary , Especially in Column and Row Under the circumstances , So do we have any good solutions ? The answer is what we are going to talk about today Wrap.
Row and Column Plight
Row and Column Can contain more than one child widget, If son widget Beyond the Row perhaps Column What will happen to the scope of ?
We use Row For example :
Widget build(BuildContext context) {
return Row(
textDirection: TextDirection.ltr,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
YellowBox(),
YellowBox(),
Expanded(
child: YellowBox(),
),
YellowBox(),
],
);
}
In the example above , We are Row Added a few YellowBox,YellowBox It's a width=100,height=50 The rectangle of :
Widget build(BuildContext context) {
return Container(
width: 100,
height: 50,
decoration: BoxDecoration(
color: Colors.yellow,
border: Border.all(),
),
);
}
Run the above code , We can get such an interface :

If in Row Add more in YellowBox What effect will it have ?
We're up there Row Add one more yellowBox:
Widget build(BuildContext context) {
return Row(
textDirection: TextDirection.ltr,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
YellowBox(),
YellowBox(),
Expanded(
child: YellowBox(),
),
YellowBox(),
YellowBox(),
],
);
}
Run to get the following interface :

You can see , because Row The son of widget That's too much , It's over Row The scope of the , An error has been reported on the interface .
To solve this problem , You need to use it Wrap Components .
Wrap The component,
Let's start with Wrap The definition of :
class Wrap extends MultiChildRenderObjectWidget
Wrap Inherited from MultiChildRenderObjectWidget, The representation can contain multiple children child.
Next is Wrap Constructor for :
Wrap({
Key? key,
this.direction = Axis.horizontal,
this.alignment = WrapAlignment.start,
this.spacing = 0.0,
this.runAlignment = WrapAlignment.start,
this.runSpacing = 0.0,
this.crossAxisAlignment = WrapCrossAlignment.start,
this.textDirection,
this.verticalDirection = VerticalDirection.down,
this.clipBehavior = Clip.none,
List<Widget> children = const <Widget>[],
}) : assert(clipBehavior != null), super(key: key, children: children);
The constructor lists Wrap Properties commonly used in .
among direction Indicates the arrangement direction of sub components .alignment Represents the way a sub component is aligned with it .spacing Represents the interval between subcomponents .
Follow spacing There's a similar one runSpacing attribute , What's the difference between the two ? Let's take a concrete example to see .
Widget build(BuildContext context) {
return Wrap(
direction: Axis.horizontal,
textDirection: TextDirection.ltr,
children: [
YellowBox(),
YellowBox(),
// Expanded(
// child: YellowBox(),
// ),
YellowBox(),
YellowBox(),
YellowBox(),
],
);
Or the example above , Here we use Wrap To replace Row, Here we use direction Options , Indicates that it is in the horizontal direction Wrap.
And then in children Added in 5 individual YellowBox.
Be careful , Not available here Expanded, Otherwise, an error will be reported , So we put Expanded Commented out , Run to get the following interface :

You can see YellowBox It is arranged in the direction of the row , If it exceeds the range of one line, it will wrap automatically , This is the same. Wrap The function of .
We are explaining Wrap When , There are also two properties mentioned , Namely spacing and runSpacing. What's the difference between the two ?
Let's take a look at spacing:
Widget build(BuildContext context) {
return Wrap(
direction: Axis.horizontal,
spacing: 10,
textDirection: TextDirection.ltr,
children: [
YellowBox(),
YellowBox(),
// Expanded(
// child: YellowBox(),
// ),
YellowBox(),
YellowBox(),
YellowBox(),
],
);
}
Let's give it first Wrap add to spacing attribute , Run to get the following interface :

You can see YellowBox Between is to use spacing For segmentation .
So if we want to Wrap When I change lines , There is also some space between two lines. What should I do ?
It's needed at this time runSpacing The attribute is :
Widget build(BuildContext context) {
return Wrap(
direction: Axis.horizontal,
spacing: 10,
runSpacing: 10,
textDirection: TextDirection.ltr,
children: [
YellowBox(),
YellowBox(),
// Expanded(
// child: YellowBox(),
// ),
YellowBox(),
YellowBox(),
YellowBox(),
],
);
}
Run to get the following interface :

Wrap It has run perfectly .
summary
Wrap You can use different direction To replace Row perhaps Column, When components may be out of range , You can consider using it Wrap 了 .
边栏推荐
- Robotframework advanced (III) integrated Jenkins operation automation use case
- The US Treasury Department approved the transaction of chemical fertilizers and agricultural products with Russia
- 騰訊大咖分享 | 騰訊Alluxio(DOP)在金融場景的落地與優化實踐
- [cloud native] development of terrain addon based on kubevera Huawei cloud
- 基于neo4j的知识图谱构建及Py2neo的使用总结
- Data transmission: Practice of batch extraction of isomorphic and heterogeneous IP data sources
- Devkit - mpc5744p configuration RTOS
- Unit MySQL appears in MySQL Solution of service could not be found
- DevSecOps研发安全实践——开发篇
- Cloud challenge of home decoration industry software
猜你喜欢

Redis 过期的数据会被立马删除么?大有玄机

Detailed explanation of thread interrupt method

Flutter 中的 offstage

After 00, he graduated from Nanjing University and planned to be a special associate researcher. Netizens quarreled after picking out their papers

Play about the workplace: Senior HR tells you what characteristics strong people in the workplace have
![[200 opencv routines] 230 LBP statistical histogram of feature description](/img/e8/477bf835984933db9ef0a49b76093b.png)
[200 opencv routines] 230 LBP statistical histogram of feature description

【OpenCV 例程200篇】230. 特征描述之 LBP 统计直方图

Digital ecological map of human resources in China - flexible employment market

朱松纯团队最新研究:机器人可与人类“推心置腹”!还说下一步要造“AI大白”...

Fuxin software appeared at the 2022 national chemical enterprise digital intelligence transformation and Development Forum
随机推荐
【直播回顾】OpenHarmony知识赋能六期第三课—OpenHarmony智能家居项目之控制面板功能实现
Redis 过期的数据会被立马删除么?大有玄机
Listbox
Website vulnerability repair service providers explain the reasons for ultra vires vulnerabilities
二叉树上的相等子树
Configure @ in vite to access files under Src
String splicing
51nod 1413 power binary
第105期:一次失败的浏览器插件开发
Comparison of xssfworkbook, sxssfworkbook and easyexcel reading Excel files
慢 SQL 分析与优化
浅谈 Slack Channel 支持的一些提高工作效率的特性
Solve the comprehensive monitoring scheme for the dynamic ring state of small and medium-sized machine rooms
解析协同办公“协同”为何意,数字化办公又如何轻松“破题”?
Use the kicad plug-in to visualize PCB welding
Musk suspends twitter acquisition, with a breakup fee of $1billion
[cloud native] development of terrain addon based on kubevera Huawei cloud
leetcode:558. 四叉树交集【四叉树dfs】
10000 words detailed SSH (SSH login principle +ssh configuration + simulated SSH secret free login)
C# 使用ToolTip控件实现气泡提示