@TOCContainer:容器
Container,容器顾名思义就是用来承载其它widget组件的控件,其作用在于给其child组件绘制、定位和调整子组件大小!
属性
alignment
对齐方式
padding
内间距。
color
容器背景色。值为一个 Color 对象,不能与 decoration 属性同时设置。
decoration
绘制在 child 之下的装饰,也就是会被 child 覆盖
设置了decoration的话,就不能设置color属性,否则会报错
foregroundDecoration
也是装饰,但是会绘制在 child 之上,也就是会覆盖 child。
width
容器宽
设置为double.infinity可以强制在宽度上撑满,不设置,则根据child和父节点两者一起布局。
height
容器高
constraints
添加到容器的child widget上的约束条件。
const BoxConstraints({
this.minWidth = 0.0,
this.maxWidth = double.infinity,
this.minHeight = 0.0,
this.maxHeight = double.infinity,
});
margin
外边距
值为一个 EdgeInsets 对象。EdgeInsets 对象即可调用EdgeInsets.all() 方法统一设置左上右下四条边的边距,也可以调用 EdgeInsets.fromLTRB() 分别设置左上右下四条边的边距。
transform
变换
child
子元素
例子:
void main() => runApp(new MyApp());
//StatelessWidget 无状态widget
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
//MaterialApp 安卓风格APP
return new MaterialApp(
title: 'welcome',
// scoffold 脚手架
home: new Scaffold(
appBar: new AppBar(
title: new Text('welcome to flutter'),
),
body: new Center(
child: Container(
constraints: BoxConstraints.expand(
height:
Theme.of(context).textTheme.headline.fontSize * 1.1 + 200.0,
),
margin: const EdgeInsets.all(10.0),
padding: const EdgeInsets.all(8.0),
alignment: Alignment.center,
color: Colors.amber[600],
width: 48,//这里设置了宽高但是没有起作用,child widget将容器Container撑开了
height: 48,
child: Text('Hello World',
style: Theme.of(context)
.textTheme
.headline
.copyWith(color: Colors.white)),
transform: Matrix4.rotationZ(0.1),
),
),
),
);
}
}