【发布时间】:2021-06-25 04:42:14
【问题描述】:
(如果此类问题已经在其他地方得到回答,请告诉我,因为我不知道用什么来形容这个问题。谢谢。)
我正在设计一个 Flutter 应用,其中包含一个显示项目列表的页面,如下图所示:
我使用ListView.builder 来迭代一个项目列表,可以向下滚动查看更多项目。现在,页眉和分隔符在页面顶部是静态的。然而,
我想要标题 Items(16) 并且分隔线可以与项目一起滚动到页面外。
- 将
ListView包装为父级 = 不理想(项目滚动不起作用); - 尝试在
ListView.builder或ListView.separated中包含标题和分隔符 = 不合适。
有什么方法可以实现吗?这是我的代码的一部分:
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
backgroundColor: appBarColor,
title: Text("Groceries"),
),
body: Column(
children: [
// Header //
Text.rich(
TextSpan(
text: "Items",
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
children: [
TextSpan(
text: " (" + items.length.toString() + ")",
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.normal,
),
),
],
),
),
// Divider //
Divider(
height: 20.0,
thickness: 1.0,
),
// Items List //
Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: items.length,
itemBuilder: (context, index) {
return CheckboxListTile(
value: true,
title: Text(items[index]),
);
}),
),
],
),
);
【问题讨论】:
标签: flutter