By Vlad
Source | Vlad (official account: fulade_me)
Wrap
stayFlutter
inWrap
Is a streaming layout control,Row
andColumn
It is easy to use in layout, but there is a disadvantage. If the number of child controls is too large, it will lead toRow
orColumn
When it cannot be loaded, an error will appear on the UI page.Wrap
This problem can be perfectly avoided. When too many lines of controls are not fully displayed,Wrap
You can wrap the display.
of courseWrap
FollowRow
andColumn
There are many similarities.
Let’s look at it firstWrap
Constructor for:
Wrap({
// Key
Key key,
//The display direction of the child control has two values: vertical direction and horizontal direction
this.direction = Axis.horizontal,
///The layout of child controls is similar to the mainaxisalignment of column
this.alignment = WrapAlignment.start,
///Distance between child controls in spindle direction
this.spacing = 0.0,
///Layout of cross direction of child controls
this.runAlignment = WrapAlignment.start,
///Cross direction spacing of child controls
this.runSpacing = 0.0,
///The alignment of the cross axis is the same as the crossaxisalignment of the column
this.crossAxisAlignment = WrapCrossAlignment.start,
///The writing direction is the same as the textdirection of column
this.textDirection,
///The layout direction of the child controls in the wrap cross axis direction
this.verticalDirection = VerticalDirection.down,
///Cutting mode
this.clipBehavior = Clip.hardEdge,
///Child controls
List<Widget> children = const <Widget>[],
})
Let’s take a look at these parameters
direction
direction
There are two parameter valuesAxis.horizontal
andAxis.vertical
, obviously it managesWrap
Is the layout horizontal or vertical.Axis.horizontal
Indicates that the child controls are laid out horizontally,Axis.vertical
Indicates that the child controls are displayed in a vertical layout.
Axis.horizontal
The effect is as follows:
Axis.vertical
The effect is as follows:
alignment
alignment
Receive oneWrapAlignment
Enumeration of types,WrapAlignment
There are six enumeration values, as follows:
WrapAlignment
Enumeration value and effect ofColumn
ofmainAxisAlignment
The effect is the same. If you want to know, you can see the previous article
enum | describe |
---|---|
start | Align with starting position |
end | Align with end position |
center | Center alignment |
spaceBetween | Divide the remaining space into n-1 copies (n is the number of child controls), and insert each copy between the child controls |
spaceEvenly | Divide the remaining space into N + 1 copies (n is the number of child controls) and distribute them evenly |
spaceAround | Divide the remaining space into 2n copies (n is the number of child controls) and put one copy up and down each child control |
WrapAlignment.start
WrapAlignment.center
WrapAlignment.end
WrapAlignment.spaceBetween
WrapAlignment.spaceEvenly
WrapAlignment.spaceAround
runAlignment
runAlignment
Receive oneWrapAlignment
Enumeration of types,WrapAlignment
There are six enumeration values (followed byalignment
The enumeration values of are the same,runAlignment
Control yes yesWrap
The alignment of the cross direction of the layout.
IfWrap
The layout is horizontal,runAlignment
Control isWrap
Vertical alignment.
verticalDirection
verticalDirection
There are two valuesVerticalDirection.down
andVerticalDirection.up
, indicating which direction to start the layout from.
VerticalDirection.down
VerticalDirection.up
Note that when set to
VerticalDirection.up
The first control isNumber 0
It starts from the lowest left.
Spacing and runspacing
spacing
Represents the distance in the spindle direction of the child control,runSpacing
The spacing of child controls in the crossing direction.
Layout in a horizontal directionWrap
Is medium,spacing
Represents the spacing between child controls in the horizontal direction,runSpacing
Represents the vertical spacing of child controls.
space space
be equal to10
Look like
space
be equal to40
Look like
runSpacing runSpacing
be equal to10
Look like
runSpacing
be equal to40
Look like
To experience the operation effect of the above example, you can go to my GitHub warehouse projectflutter_app
->lib
->routes
->wrap_page.dart
View it, and you can download it, run it and experience it.