flutter之Container组件属性

代码片段:

new Container(
  //宽度
  width:100,
  //高度
  height:100,
  //有时在不确定宽高的情况下需要设置Container的最大或最小宽高,可以通过Container的constraints属性来设置
  constraints: new BoxConstraints.expand(
    height:Theme.of(context).textTheme.display1.fontSize * 1.1 + 200.0,
    //或者
    minWidth: 180,
    minHeight: 50,
  ),
  //decoration可以设置边框、背景色、背景图片、圆角等属性,非常实用
  decoration: new BoxDecoration(
    border: new Border.all(width: 2.0, color: Colors.red),
    color: Colors.grey,
    //背景垂直渐变色
    gradient: LinearGradient(
          begin: const Alignment(0.0, -1.0),
          end: const Alignment(0.0, 0.6),
          colors: <Color>[
            const Color(0xffef5350),
            const Color(0x00ef5350)
          ],
    ),
    //背景水平渐变色
    gradient: LinearGradient(
          begin: const Alignment(-1.0, 0.0),
          end: const Alignment(0.6, 0.0),
          colors: <Color>[
            const Color(0xffef5350),
            const Color(0x00ef5350)
          ],
    ),
    //盒阴影
    boxShadow: [
                BoxShadow (
                  color: const Color(0xcc000000),
                  offset: Offset(0, 2),
                  blurRadius: 4,
                ),
                BoxShadow (
                  color: const Color(0x80000000),
                  offset: Offset(0, 6),
                  blurRadius: 20,
                ),
    ],
    //圆形
    shape: BoxShape.circle,
    //圆角
    borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
    image: new DecorationImage(
      image: new NetworkImage('http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg'),
      centerSlice: new Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
    ),
  ),
  margin: const EdgeInsets.all(8.0),
  padding: const EdgeInsets.all(8.0),
  //规定子组件的对齐方式
  alignment: Alignment.center,
  //定义子组件(子元素)
  child: new Text('Hello World',
  //整个container的样式
  style: Theme.of(context).textTheme.display1.copyWith(color: Colors.black)),
  transform: new Matrix4.rotationZ(0.3),
)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值