flutter 控件 center

Center继承自Align,只不过是将alignment设置为Alignment.center,

其他属性例如widthFactor、heightFactor,布局行为,都与Align完全一样,在这里就不再单独做介绍了。

Center源码如下,没有设置alignment属性,是因为Align默认的对齐方式就是居中。

1
2
3
4
5
class Center extends Align {
/// Creates a widget that centers its child.
const Center({ Key key, double widthFactor, double heightFactor, Widget child })
: super(key: key, widthFactor: widthFactor, heightFactor: heightFactor, child: child);
}