我可以从ListView中显示超出容器限制的项目吗?

问题描述 投票:0回答:1

在我的屏幕上,我的顶部和下面有一个透明的容器,我有一个带卡片的ListView。现在,当我向下滚动列表时,列表顶部的项目显然会被切除并消失。有没有办法滚动并使这些项目在透明容器中可见(因此超出了容器的正常限制)?

 class MyHomePage extends StatelessWidget {
  final List items = ['1', '2', '3', '4', '5', '6', '7', '8','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7',];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(),
        body: Column(
          children: <Widget>[
            Container(
                color: Colors.transparent,
                height: 200,
                child: Center(child: Text('Transparent Box'))),
            Expanded(child: ListView.builder(
                itemCount: items.length,
                itemBuilder: (context, index) {
                  return Card(child: Text(items[index]));
                }))
          ],
        ));
  }
}

我尝试使用堆栈,但是ListView容器从头开始显示在透明框中。但我仍然希望“起点”在该框下方。希望您能按照我的想法和解释。感谢您的帮助,谢谢!

flutter flutter-layout
1个回答
1
投票

将您的容器和ListView添加到堆栈中,然后将顶部填充添加到列表中,如下所示:

Stack(
      children: <Widget>[
        Expanded(child: ListView.builder(
            padding: EdgeInsets.only(top: 200),
            itemCount: items.length,
            itemBuilder: (context, index) {
              return Card(child: Text(items[index]));
            })),
            Container(
            color: Colors.transparent,
            height: 200,
            child: Center(child: Text('Transparent Box'))),
      ],
    ));
© www.soinside.com 2019 - 2024. All rights reserved.