You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让ListView中InkWell的水波纹与ListView圆角边框匹配

解决InkWell水波纹与带圆角ListView边框重合的问题

问题描述

当前带圆角边框的ListView中,Item的InkWell水波纹超出了圆角范围,需要让水波纹贴合ListView的边框。

当前效果:
当前效果

解决方法

针对列表的第一个和最后一个Item设置对应方向的圆角,中间Item保持直角,同时利用InkWell的borderRadius属性限制水波纹范围,使其与ListView整体边框对齐。注意因为设置了reverse: true,列表渲染顺序倒转,需调整圆角的对应位置。

修改后的代码

final borderRadius = BorderRadius.circular(20.0);
return RefreshIndicator(
  onRefresh: _refreshList,
  child: Padding(
    padding: const EdgeInsets.only(top: 5, right: 16, left: 16),
    child: DecoratedBox(
      decoration: BoxDecoration(
        color: AppColors.mainGreen,
        borderRadius: borderRadius,
      ),
      child: ClipRRect(
        borderRadius: borderRadius,
        child: ListView.builder(
          controller: _scrollController,
          reverse: true,
          physics: const AlwaysScrollableScrollPhysics(),
          itemCount: state.notes.length,
          itemBuilder: (BuildContext context, int index) {
            final note = state.sortedNotes[index];
            BorderRadius itemBorderRadius;
            
            // 适配reverse=true的渲染顺序:index=0是列表底部,最后一个index是列表顶部
            if (index == 0) {
              itemBorderRadius = BorderRadius.only(
                bottomLeft: borderRadius.bottomLeft,
                bottomRight: borderRadius.bottomRight,
              );
            } else if (index == state.notes.length - 1) {
              itemBorderRadius = BorderRadius.only(
                topLeft: borderRadius.topLeft,
                topRight: borderRadius.topRight,
              );
            } else {
              itemBorderRadius = BorderRadius.zero;
            }
            
            return InkWell(
              onTap: () => _onNoteTab(note.id),
              // 限制水波纹的圆角范围
              borderRadius: itemBorderRadius,
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Row(
                  children: [
                    SvgPicture.asset(
                      note.mood.selectedIcon,
                      height: 50,
                      width: 50,
                    ),
                    const SizedBox(width: 13),
                    Expanded(
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          _MoodRow(note: note),
                          _SleepAndFoodRow(note: note),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            );
          },
        ),
      ),
    ),
  ),
);

关键说明

  1. 外层ClipRRect保留,确保ListView整体视觉呈现圆角边框;
  2. 通过InkWell的borderRadius属性,为不同位置的Item设置匹配的圆角,直接限制水波纹的扩散范围;
  3. 适配reverse: true的特性,调整首尾Item的圆角方向,保证整体视觉统一。

内容的提问来源于stack exchange,提问作者MipZ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:53:11