我正在努力与所有国家建立一份名单,我需要为所有国家增加一条灰色底线.

但当我try 实现此功能时,出现了一个问题.这条边框的宽度从左到右都被切断了,我不知道为什么.

如何将这个边框扩展为ListView的全部重量?

I want this

但我只能得到这样的结果:

This is how it looks like with my code

这是我的代码:

class Countries extends StatefulWidget {
  const Countries({super.key});

  @override
  State<Countries> createState() => _CountriesState();
}

class _CountriesState extends State<Countries> {
  @override
  Widget build(BuildContext context) {
    return SizedBox(
            height: 235,
            child: Padding(
                    padding: const EdgeInsets.only(top: 8, left: 12, right: 12),
                    child: Container(
                      decoration: BoxDecoration(
                          border: Border.all(color: AppColors.gray2F2D2D),
                          borderRadius: BorderRadius.circular(8.0)),
                      child: Column(
                        children: [
                          Flexible(
                            child: ListView.builder(
                              itemCount: countries.length,
                              scrollDirection: Axis.vertical,
                              shrinkWrap: true,
                              itemBuilder: (context, index) {
                                return ListTile(
                                  title: Container(
                                    decoration: BoxDecoration(
                                      border: Border(
                                        bottom: BorderSide(width: 1, color: AppColors.gray2F2D2D)
                                      )
                                    ),
                                    child: Padding(
                                      padding: const EdgeInsets.only(
                                        top: 16,
                                        bottom: 16,
                                        left: 20
                                      ),
                                      child: Text(
                                        countries[index],
                                        style: const TextStyle(
                                            color: AppColors.grayA0A0A0,
                                            fontSize: 16,
                                            fontWeight: FontWeight.w500),
                                      ),
                                    ),
                                  ),
                                );
                              },
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
          ),
  }
}

推荐答案

try 在您的ListTile小部件中添加contentPadding: EdgeInsets.zero:

return ListTile(
   contentPadding: EdgeInsets.zero,
   // your item widget
)

而且,我看到你外面有一个Padding左右12,如果你不需要它就把它移走,然后你的边界线会全屏

Flutter相关问答推荐

修复容器`Text`和容器表单之间的重叠

手势捕获的异常:类型';Double';不是类型转换中类型';Double';的子类型

我可以在iOS设备上使用Ffltter实现Google Pay按钮吗?

本机调试符号包含无效的目录调试符号.目前仅支持Android ABI

如何实现Flutter 梳理机图像的小量移动

Flutter Riverpod,将默认的BTC值改写为我的新状态

从.gitignore中排除.fvm/fvm_config.json

如何在Flutter 安全存储器中存储对象值?

Flutter 火焰相机抖动已弃用

什么最接近 Dart 的 List.asMap().forEach() 返回列表?

如何停止折线图的抖动

java.lang.IncompatibleClassChangeError:找到接口 com.google.android.gms.location.SettingsClient,

按下 Command+W 时关闭窗口

如何将金钱格式化为数以百万计的Flutter 动?

一个或多个插件需要更高的 Android SDK 版本

Flutter Web Responsiveness 效率不高

如何将 pushNamed 与 Dismissible Widget 一起使用并查看背景透明第一页

如何避免与架构相关的 Google Play Console 问题

在Flutter 中设置文本长度的宽度

迁移到较新的 BloC 版本问题