Flutter 视频详情头部模块组件封装与布局技巧

ListView 清除padding

padding: EdgeInsets.all(0)

布局技巧

  1. 为了减少嵌套,尽量将相关的Widget抽离成方法

设置圆形图片

设置技巧:图片宽和高设置为 borderRadius 的2倍

ClipRRect(
    borderRadius: BorderRadius.circular(15),
    child: Image.network(owner.face, width: 30, height: 30),
),            

填充 Row、Column 剩余可用空间

使用 Flexible 或者 ExpandedFlexible 不强制子组件填充剩余可用空间

封装视频详情头部模块组件

在这里插入图片描述

class VideoHeader extends StatelessWidget {
  final Owner owner;

  const VideoHeader({Key key, @required this.owner}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15, top: 15),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Row(
            children: [
              // 用户头像
              ClipRRect(
                borderRadius: BorderRadius.circular(15),
                child: Image.network(owner.face, width: 30, height: 30),
              ),
              Padding(
                padding: EdgeInsets.only(left: 8),
                child: Column(
                  children: [
                    // 用户信息
                    Text(
                      owner.name,
                      style: TextStyle(
                          fontSize: 13,
                          color: primary,
                          fontWeight: FontWeight.bold),
                    ),
                    Text(
                      '${countFormat(owner.fans)}粉丝',
                      style: TextStyle(fontSize: 10, color: Colors.grey),
                    )
                  ],
                ),
              ),
            ],
          ),
          // 关注按钮
          MaterialButton(
            onPressed: () {},
            color: primary,
            height: 24,
            minWidth: 50,
            child: Text(
              '+ 关注',
              style: TextStyle(color: Colors.white, fontSize: 13),
            ),
          )
        ],
      ),
    );
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值