Flutter组件之Container
属性
必选
1. Widget => child 所包含的组件(孩子)
可选
1. width、height => double 宽高值,注意加.0(例如25.0)
2. alignment => Alignment 子组件的布局(即孩子在容器内的对齐)
3. color => Color 背景颜色
4. margin => EdgeInsetsGeometry 外边距
5. padding => EdgeInsetsGeometry 内边距
6. decoration => 各种Decoration 孩子背后的装饰
例子
Container(
child: Text(
"我是一个文本",
style: TextStyle(fontSize: 25.0),
),
height: 200.0,
alignment: Alignment.center,
margin: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
decoration: new BoxDecoration(//带有边框和渐变色背景
gradient: const LinearGradient(
colors: [Colors.red, Colors.orange, Colors.yellow]
),
border: Border.all(width: 2.0, color: Colors.green)
),
)