Flutter flex布局其实是借鉴CSS flex布局,有一篇非常好的文章推荐给大家。
1. CSS
container
items
order
flex-redirection
flex-grow
flex-wrap
justify-content
align-self
align-items
align-content
2. Flutter
源码 flex.dart :FlexFit 、 MainAxisSize 、MainAxisAlignment 、CrossAxisAlignment
/// How the child is inscribed into the available space.////// See also:////// * [RenderFlex], the flex render object./// * [Column], [Row], and [Flex], the flex widgets./// * [Expanded], the widget equivalent of [tight]./// * [Flexible], the widget equivalent of [loose].enum FlexFit {/// The child is forced to fill the available space.////// The [Expanded] widget assigns this kind of [FlexFit] to its child.tight,/// The child can be at most as large as the available space (but is/// allowed to be smaller).////// The [Flexible] widget assigns this kind of [FlexFit] to its child.loose,}/// How much space should be occupied in the main axis.////// During a flex layout, available space along the main axis is allocated to/// children. After allocating space, there might be some remaining free space./// This value controls whether to maximize or minimize the amount of free/// space, subject to the incoming layout constraints.////// See also:////// * [Column], [Row], and [Flex], the flex widgets./// * [Expanded] and [Flexible], the widgets that controls a flex widgets'/// children's flex./// * [RenderFlex], the flex render object./// * [MainAxisAlignment], which controls how the free space is distributed.enum MainAxisSize {/// Minimize the amount of free space along the main axis, subject to the/// incoming layout constraints.////// If the incoming layout constraints have a large enough/// [BoxConstraints.minWidth] or [BoxConstraints.minHeight], there might still/// be a non-zero amount of free space.////// If the incoming layout constraints are unbounded, and any children have a/// non-zero [FlexParentData.flex] and a [FlexFit.tight] fit (as applied by/// [Expanded]), the [RenderFlex] will assert, because there would be infinite/// remaining free space and boxes cannot be given infinite size.min,/// Maximize the amount of free space along the main axis, subject to the/// incoming layout constraints.////// If the incoming layout constraints have a small enough/// [BoxConstraints.maxWidth] or [BoxConstraints.maxHeight], there might still/// be no free space.////// If the incoming layout constraints are unbounded, the [RenderFlex] will/// assert, because there would be infinite remaining free space and boxes/// cannot be given infinite size.max,}/// How the children should be placed along the main axis in a flex layout.////// See also:////// * [Column], [Row], and [Flex], the flex widgets./// * [RenderFlex], the flex render object.enum MainAxisAlignment {/// Place the children as close to the start of the main axis as possible.////// If this value is used in a horizontal direction, a [TextDirection] must be/// available to determine if the start is the left or the right.////// If this value is used in a vertical direction, a [VerticalDirection] must be/// available to determine if the start is the top or the bottom.start,/// Place the children as close to the end of the main axis as possible.////// If this value is used in a horizontal direction, a [TextDirection] must be/// available to determine if the end is the left or the right.////// If this value is used in a vertical direction, a [VerticalDirection] must be/// available to determine if the end is the top or the bottom.end,/// Place the children as close to the middle of the main axis as possible.center,/// Place the free space evenly between the children.spaceBetween,/// Place the free space evenly between the children as well as half of that/// space before and after the first and last child.spaceAround,/// Place the free space evenly between the children as well as before and/// after the first and last child.spaceEvenly,}/// How the children should be placed along the cross axis in a flex layout.////// See also:////// * [Column], [Row], and [Flex], the flex widgets./// * [RenderFlex], the flex render object.enum CrossAxisAlignment {/// Place the children with their start edge aligned with the start side of/// the cross axis.////// For example, in a column (a flex with a vertical axis) whose/// [TextDirection] is [TextDirection.ltr], this aligns the left edge of the/// children along the left edge of the column.////// If this value is used in a horizontal direction, a [TextDirection] must be/// available to determine if the start is the left or the right.////// If this value is used in a vertical direction, a [VerticalDirection] must be/// available to determine if the start is the top or the bottom.start,/// Place the children as close to the end of the cross axis as possible.////// For example, in a column (a flex with a vertical axis) whose/// [TextDirection] is [TextDirection.ltr], this aligns the right edge of the/// children along the right edge of the column.////// If this value is used in a horizontal direction, a [TextDirection] must be/// available to determine if the end is the left or the right.////// If this value is used in a vertical direction, a [VerticalDirection] must be/// available to determine if the end is the top or the bottom.end,/// Place the children so that their centers align with the middle of the/// cross axis.////// This is the default cross-axis alignment.center,/// Require the children to fill the cross axis.////// This causes the constraints passed to the children to be tight in the/// cross axis.stretch,/// Place the children along the cross axis such that their baselines match.////// If the main axis is vertical, then this value is treated like [start]/// (since baselines are always horizontal).baseline,}
