flutter

Expanded使用与类似与Column,Row,Flex等展示多个组件集合的组件,Expanded包含的组件可以占据剩余的空间。

在一个Row组件里面展示3个Container组件,固定了后两个组件的宽高,第一个组件就撑满屏幕,占据

Row(
            mainAxisAlignment: MainAxisAlignment.end,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              Expanded(// Expanded包一下,可以撑满剩余空间
                child: Container(
                  color: Colors.amber,
                  height: 100,
                ),
              ),
              Container(
                width: 50,
                height: 100,
                color: Colors.red,
              ),
              Container(
                width: 50,
                height: 100,
                color: Colors.cyan,
              )
            ],
          ),

case1

 屏幕左边是文字,最右边是一个按钮,文字数据是服务器数据返回的,且多行显示。

String _title = '这里的文字是动态的展示多行的数据,Expanded可以包裹左边的Text组件,右边的btn控制大小';
class _Test extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
          Expanded(child: Text('$_title')),
          SizedBox(
            width: 10,
          ),
          Container(
            width: 60,
            height: 60,
            child: RaisedButton(
              onPressed: () {},
              child: Text('订购'),
            ),
          ),
        ],
      ),
    );
  }
}

case2:按比例分割屏幕空间

举例:1:2:1

Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Expanded(
          flex: 1,
          child: Container(
            height: 40,
            color: Colors.amber,
            child: Text('amber'),
          ),
        ),Expanded(
          flex: 2,
          child: Container(
            height: 40,
            color: Colors.red,
            child: Text('red'),
          ),
        ), Expanded(
          flex: 1,
          child: Container(
            height: 40,
            color: Colors.cyan,
            child: Text('cyan'),
          ),
        ),
      ],
    );

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值