flutter组件之Stack

stack组件可以实现定位问题,如果您想以简单的方式重叠多个子级,例如具有一些文本和图像,并用渐变和一个附加在底部的按钮覆盖,则该类很有用。

// SizedBox组件能强制子控件具有特定宽度、高度或两者都有,使子控件设置的宽高失效
// width: 100.0,//宽度
// height: 100.0,//高度
// child:  Container(
//   width: 200.0,
//   height: 200.0,
//   color: Color(0xffff0000),
// ),
SizedBox(
  width: 250,
  height: 250,
  child: new Stack(
    children: <Widget>[
      //定位组件
      //left: 20.0
      //top: 10.0
      //right: 10.0
      //bottom: 10.0
      //width: 10.0
      //height: 20.0
      //child: new Text()
      Positioned(
        top: 100.0,
        child: Container(
          color: Colors.blue,
          child: Text("第一个组件"),
        ),
      ),
      Positioned(
        top: 200,
        right: 100,
        child: Container(
          color: Colors.yellow,
          child: Text("第二个组件"),
        ),
      ),
      Positioned(
        left: 100.0,
        child: Container(
          color: Colors.red,
          child: Text("第三个组件"),
        ),
      ),
      new Container(
        width: 250,
        height: 250,
        color: Colors.white,
      ),
      new Container(
        padding: EdgeInsets.all(5.0),
        //对齐方式
        alignment: Alignment.bottomCenter,
        decoration: BoxDecoration(
          //渐变色
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: <Color>[
              Colors.black.withAlpha(0),
              Colors.black12,
              Colors.black45
            ],
          ),
        ),
        child: new Text(
          "Foreground Text",
          style: TextStyle(color: Colors.white, fontSize: 20.0),
        ),
      ),
    ],
  ),
)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值