我遇到了一个小问题,这个问题肯定很容易解决,但我找不到任何解决方案.所有建议的subjetc都是关于自定义背景的. 以下是我的代码:

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

  @override
  State<HomeTest> createState() => _HomeTestState();
}

class _HomeTestState extends State<HomeTest> {
  final courantController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    final soldes = FirebaseFirestore.instance.collection('Soldes');
    return Scaffold(
        appBar: AppBar(title: const Text('Test')),
        body: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(10),
            child: Column(
              children: [
                const Text("text"),
                const SizedBox(height: 20),
                const Text(
                  'another text',
                  textAlign: TextAlign.center,
                ),
                Container(
                  color: Colors.white,
                  height: 50,
                ),
                const SizedBox(height: 10),
                Container(
                    color: Colors.white,
                    height: 100,
                    child: Text('Container text')),
                const AnnoyingList(),
              ],
            ),
          ),
        ));
  }
}

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

  @override
  State<AnnoyingList> createState() => _AnnoyingListState();
}

class _AnnoyingListState extends State<AnnoyingList> {
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 250,
      child: ListView(children: [
        ListTile(
          tileColor: const Color.fromARGB(93, 88, 127, 158),
          shape: RoundedRectangleBorder(
            side: const BorderSide(width: 2),
            borderRadius: BorderRadius.circular(50), //<-- SEE HERE
          ),
          title: const Text('Tile 1'),
        ),
        const SizedBox(height: 20),
        ListTile(
          tileColor: const Color.fromARGB(93, 88, 127, 158),
          shape: RoundedRectangleBorder(
            side: const BorderSide(width: 2),
            borderRadius: BorderRadius.circular(50), //<-- SEE HERE
          ),
          title: const Text('Tile 2'),
        ),
        const SizedBox(height: 20),
        ListTile(
          tileColor: const Color.fromARGB(93, 88, 127, 158),
          shape: RoundedRectangleBorder(
            side: const BorderSide(width: 2),
            borderRadius: BorderRadius.circular(50), //<-- SEE HERE
          ),
          title: const Text('Tile 3'),
        ),
        const SizedBox(height: 20),
        ListTile(
          tileColor: const Color.fromARGB(93, 88, 127, 158),
          shape: RoundedRectangleBorder(
            side: const BorderSide(width: 2),
            borderRadius: BorderRadius.circular(50), //<-- SEE HERE
          ),
          title: const Text('Tile 4'),
        ),
        const SizedBox(height: 20),
        ListTile(
          tileColor: const Color.fromARGB(93, 88, 127, 158),
          shape: RoundedRectangleBorder(
            side: const BorderSide(width: 2),
            borderRadius: BorderRadius.circular(50), //<-- SEE HERE
          ),
          title: const Text('Tile 5'),
        ),
        const SizedBox(height: 20),
        ListTile(
          tileColor: const Color.fromARGB(93, 88, 127, 158),
          shape: RoundedRectangleBorder(
            side: const BorderSide(width: 2),
            borderRadius: BorderRadius.circular(50), //<-- SEE HERE
          ),
          title: const Text('Tile 6'),
        ),
      ]),
    );
  }
}

问题是ListView位于SizedBox之外,并且在SizedBox之外是可见的.

在移动列表之前

enter image description here

在移动列表之后

enter image description here

正如你所看到的,我试图添加容器,但很明显,我一放东西在上面,它就会适应它的宽度.对于列表保留在SizedBox中有什么简单的解决方案吗? 看起来背景是透明的,但我没能通过改变应用程序的主题来解决这个问题… 谢谢!

推荐答案

用卡片把每一张单子都包起来

Card(
child: ListTile(//...)
//...
)

Flutter相关问答推荐

ListTile未正确显示在flutter中

自定义ItemBuilderFlutter

Flutter creating Constant.dart InputDecoration section put pass in hintText

如何将Will POP示波器转换为POP数据抖动的POP示波器

为什么当我使用Riverpod更新状态时,列表会被刷新?

在背景图像上排列定位徽标

如何从RealmResults获取Flutter Flutter 流?

如何使listview.builder在筛选列表后实时更新

SliverAppbar 呈蓝色

Flutter: pie_chart 插件动画滚动问题

使用堆栈的自定义按钮

如何在 Flutter 中的 BackdropFilter.blur 中制作一个 100x100 的清晰孔

有什么办法可以消除Flutter 中的传递依赖?

如何对齐卡片小部件中的图标按钮?

如何在 flutter 的 onChanged(更改字符)处更改 TextField 边框 colored颜色 ?

无效的 depfile: C:\xxx\xxx\Flutter\project_name\.dart_tool\flutter_build\df4b308df1ee4bce22c56c71751554d1\kernel_snapshot.d 无效

Flutter - 使用 pin 进行身份验证

Flutter如何从左到右连续 Select 多个列表项而不跳过任何

参数类型Future>不能分配给参数类型Future>?

Flutter ListView builder 未使用新数据更新