Flutter基础控件:Container

@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),
          ),
        ),
      ),
    );
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值