Expanded 这是个用来让子项具有伸缩能力的widget
Expanded继承自Flexible
,但是它们两个的区别并不大,看它们的构造方法:
class Expanded extends Flexible {
/// Creates a widget that expands a child of a [Row], [Column], or [Flex]
/// expand to fill the available space in the main axis.
const Expanded({
Key key,
int flex: 1,
@required Widget child,
}) : super(key: key, flex: flex, fit: FlexFit.tight, child: child);
}
class Flexible extends ParentDataWidget<Flex> {
/// Creates a widget that controls how a child of a [Row], [Column], or [Flex]
/// flexes.
const Flexible({
Key key,
this.flex: 1,
this.fit: FlexFit.loose,
@required Widget child,
}) : super(key: key, child: child);
……
}
可见它们两个的默认灵活系数是一样的,但是fit参数不同,Expanded是默认要占满分配的空间的,而Flexible则默认不需要