flutter listview 设置分割线

阳光穿透心脏的1/2处 2023-07-11 15:19 86阅读 0赞

使用ListView.separated,就很简单了

  1. ListView.separated(
  2. scrollDirection: direction,
  3. itemBuilder: (context, index) {
  4. final Axis slidableDirection =
  5. direction == Axis.horizontal ? Axis.vertical : Axis.horizontal;
  6. return _getSlidableWithLists(context, index, slidableDirection);
  7. },
  8. itemCount: list.length,
  9. separatorBuilder: (BuildContext context, int index) =>
  10. Divider(height: 1.0, color: AppColors.separator),
  11. );

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

  1. ListView.builder(
  2. shrinkWrap: true,
  3. physics: NeverScrollableScrollPhysics(),
  4. itemBuilder: (BuildContext context, int index) =>
  5. GroupContactItem(_headData[index], groupModel),
  6. itemCount: _headData.length)
  7. ],

效果如下:

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

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

csdn:https://me.csdn.net/beyondforme

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

发表评论

表情:
评论列表 (有 0 条评论,86人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ListView分割线

    重新定义分割线Drawable的Bounds 首先,需要清楚一个事实:出现以上情况的矛盾点,是官方ListView的分割线属性不支持左右留白。所以最佳的解决方案,就是使得官方