When to use main Axis Alignment and cross Axis Alignment?
When to use main Axis Alignment and cross Axis Alignment?
In Flutter, mainAxisAlignment
and crossAxisAlignment
are used to control the alignment of child widgets within a Row
or Column
widget. The main axis is the axis along which the children are laid out, while the cross axis is perpendicular to the main axis.
When to use mainAxisAlignment
:
mainAxisAlignment
to align the children along the main axis of a Row
or Column
.Row
, mainAxisAlignment
aligns the children horizontally.Column
, mainAxisAlignment
aligns the children vertically.mainAxisAlignment
include start
, end
, center
, spaceBetween
, spaceAround
, and spaceEvenly
.When to use crossAxisAlignment
:
crossAxisAlignment
to align the children along the cross axis of a Row
or Column
.Row
, crossAxisAlignment
aligns the children vertically.Column
, crossAxisAlignment
aligns the children horizontally.crossAxisAlignment
include start
, end
, center
, stretch
, and baseline
.Here are some examples of when to use mainAxisAlignment
and crossAxisAlignment
:
Row
with multiple children and want to align them vertically in the center, use `crossAxisAlignment: Cross...entry
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào