flutter listview 设置分割线

在Flutter中,可以通过ListView.separated方便地设置分割线,但若使用ListView.builder,则需在itemBuilder内手动添加。示例展示了如何实现效果,详情可见作者在简书、优快云和掘金的分享。

使用ListView.separated,就很简单了

  ListView.separated(
        scrollDirection: direction,
        itemBuilder: (context, index) {
          final Axis slidableDirection =
              direction == Axis.horizontal ? Axis.vertical : Axis.horizontal;
          return _getSlidableWithLists(context, index, slidableDirection);
        },
        itemCount: list.length,
        separatorBuilder: (BuildContext context, int index) =>
            Divider(height: 1.0, color: AppColors.separator),
      );

如果使用ListView.builder,没有这个属性,需要自己在itemBuilder中增加下划线

ListView.builder(
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemBuilder: (BuildContext context, int index) =>
                  GroupContactItem(_headData[index], groupModel),
              itemCount: _headData.length)
        ],

效果如下:


喜欢可以加Q群号:913934649,点赞,评论;

简书: https://www.jianshu.com/u/88db5f15770d

csdn:https://me.youkuaiyun.com/beyondforme

掘金:https://juejin.im/user/5e09a9e86fb9a016271294a7

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值