Flex
类似于Android
中的LinearLayout
,构造方法如下:
Flex({
Key key,
@required this.direction,
this.mainAxisAlignment = MainAxisAlignment.start,
this.mainAxisSize = MainAxisSize.max,
this.crossAxisAlignment = CrossAxisAlignment.center,
this.textDirection,
this.verticalDirection = VerticalDirection.down,
this.textBaseline,
List<Widget> children = const <Widget>[],
}) : assert(direction != null),
assert(mainAxisAlignment != null),
assert(mainAxisSize != null),
assert(crossAxisAlignment != null),
assert(verticalDirection != null),
assert(crossAxisAlignment != CrossAxisAlignment.baseline || textBaseline != null),
super(key: key, children: children);
direction
属性指定children
的排列方向,类似于LinearLayout
的orientation
,direction
只有两个枚举值:
enum Axis {
//水平方向
horizontal,
//竖直方向
vertical,
}
textDirection属性指定水平方向上start、end对齐方式的具体含义。只有两个枚举值:
enum TextDirection {
// right to left
rtl,
// left to right
ltr,
}
verticalDirection属性指定竖直方向上start、end对齐方式的具体含义。只有两个枚举值:
enum VerticalDirection {
// down to up
up,
//up to down
down,
}
当交叉轴(与主轴垂直的轴)的对齐方式为baseline(基准线对齐)时,textBaseline用于指定提供基准线的文本的类型,只有两个枚举值:
enum TextBaseline {
/// 字母文字,如英文
alphabetic,
/// 表意文字,如汉语
ideographic,
}
mainAxisAlignment
属性指定主轴方向(direction
指定的方向)的对齐方式,枚举值如下:
enum MainAxisAlignment {
start,
end,
center,
spaceBetween,
spaceAround,
spaceEvenly,
}
start
Axis.horizontal
,MainAxisAlignment.start
的具体含义由textDirection
属性决定。textDirection
为ltr,则表示左对齐,textDirection
为rtl,则表示右对齐。MainAxisAlignment.start
的具体含义由verticalDirection
属性决定。verticalDirection
为down,则表示顶部对齐,verticalDirection
为up,则表示底部对齐。end
Axis.horizontal
,end
的具体含义由textDirection
属性决定。textDirection
为,则表示左对齐,textDirection
为rtl,则表示右对齐。MainAxisAlignment.start
的具体含义由verticalDirection
属性决定。verticalDirection
为down,则表示顶部对齐,verticalDirection
为up,则表示底部对齐。center
spaceBetween
spaceEvenly
spaceAround