ListView 内的 ExpansionTile - 页面不滚动
ExpansionTile inside ListView - page not scrolling
我遇到了页面滚动问题。我正在向用户展示每天分组的交易。
所以 ExpansionTile 里面会有多个项目。
我先从数据库中抽出几天时间,然后再抽取当天完成的交易。
下面是我的页面的工作方式
- 获取所有记录
- 获取天数并放入一个列表(天数列表)
- 在此列表(天列表)中使用 for 循环加载主要扩展块
- 当我们执行 for 循环时,获取当天的交易并加载到另一个数组中
- 将子列表作为子列表绑定到 ExpansionTile。
我的视图正在正确加载,但是当我打开 ExpansionTile 的子项时,我无法滚动页面。请查看视频以获得更清晰的理解。
https://drive.google.com/file/d/1EVETVRHx0vZqiGryrcxUR0klrEX8Y63G/view?usp=sharing
我的代码如下,
Widget build(BuildContext context) {
return new Scaffold(
body: FutureBuilder(
future: getTransactions(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
} else if (feedItemsParent.isEmpty) {
return noRecordsDialogue(context, 'No transactions record', '');
} else if (feedItemsParent.length == 0) {
return noRecordsDialogue(context, 'No transactions record', '');
} else {
return new ListView.builder(
shrinkWrap: true,
itemCount: feedItemsParent.length,
itemBuilder: (BuildContext ctxt, int index) =>
buildBody(ctxt, index));
}
},
),
);
}
下面是buildBody函数。
Widget buildBody(BuildContext ctxt, int index) {
return new custom.ExpansionTile(
initiallyExpanded: true,
trailing: new Container(width: 20),
headerBackgroundColor: Color(0xFFeff0f1),
title: Text(
feedItemsParent[index].transactiondatesmall.toString(),
style: TextStyle(
fontSize: 16,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
children: <Widget>[
buildTransactionList(
feedItemsParent[index].transactiondatesmall.toString()),
],
);
}
下面是我如何带走所有子项并将它们绑定到 ExpansionTile 中。
buildTransactionList(dtCompare) {
if (feedItems.length == 0) {
return noRecordsDialogue(context, 'No transactions record', '');
} else {
List<UserTransaction> feedItemsChild = [];
for (int j = 0; j < feedItems.length; j++) {
if (feedItems[j].transactiondatesmall == dtCompare) {
feedItemsChild.add(feedItems[j]);
}
}
return ListView(
padding: const EdgeInsets.only(bottom: 16.0),
shrinkWrap: true,
children: feedItemsChild,
);
}
}
提前致谢。
最后我能够使用下面给出的答案解决这个问题 link。根据答案中给出的内容更改了我的代码,因为我的要求相似度为 80%。
谢谢。
只需将此代码添加到 ListView.Builder 即可解决此问题
physics: const NeverScrollableScrollPhysics()
我遇到了页面滚动问题。我正在向用户展示每天分组的交易。 所以 ExpansionTile 里面会有多个项目。
我先从数据库中抽出几天时间,然后再抽取当天完成的交易。 下面是我的页面的工作方式
- 获取所有记录
- 获取天数并放入一个列表(天数列表)
- 在此列表(天列表)中使用 for 循环加载主要扩展块
- 当我们执行 for 循环时,获取当天的交易并加载到另一个数组中
- 将子列表作为子列表绑定到 ExpansionTile。
我的视图正在正确加载,但是当我打开 ExpansionTile 的子项时,我无法滚动页面。请查看视频以获得更清晰的理解。 https://drive.google.com/file/d/1EVETVRHx0vZqiGryrcxUR0klrEX8Y63G/view?usp=sharing
我的代码如下,
Widget build(BuildContext context) {
return new Scaffold(
body: FutureBuilder(
future: getTransactions(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
} else if (feedItemsParent.isEmpty) {
return noRecordsDialogue(context, 'No transactions record', '');
} else if (feedItemsParent.length == 0) {
return noRecordsDialogue(context, 'No transactions record', '');
} else {
return new ListView.builder(
shrinkWrap: true,
itemCount: feedItemsParent.length,
itemBuilder: (BuildContext ctxt, int index) =>
buildBody(ctxt, index));
}
},
),
);
}
下面是buildBody函数。
Widget buildBody(BuildContext ctxt, int index) {
return new custom.ExpansionTile(
initiallyExpanded: true,
trailing: new Container(width: 20),
headerBackgroundColor: Color(0xFFeff0f1),
title: Text(
feedItemsParent[index].transactiondatesmall.toString(),
style: TextStyle(
fontSize: 16,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
children: <Widget>[
buildTransactionList(
feedItemsParent[index].transactiondatesmall.toString()),
],
);
}
下面是我如何带走所有子项并将它们绑定到 ExpansionTile 中。
buildTransactionList(dtCompare) {
if (feedItems.length == 0) {
return noRecordsDialogue(context, 'No transactions record', '');
} else {
List<UserTransaction> feedItemsChild = [];
for (int j = 0; j < feedItems.length; j++) {
if (feedItems[j].transactiondatesmall == dtCompare) {
feedItemsChild.add(feedItems[j]);
}
}
return ListView(
padding: const EdgeInsets.only(bottom: 16.0),
shrinkWrap: true,
children: feedItemsChild,
);
}
}
提前致谢。
最后我能够使用下面给出的答案解决这个问题 link。根据答案中给出的内容更改了我的代码,因为我的要求相似度为 80%。
谢谢。
只需将此代码添加到 ListView.Builder 即可解决此问题
physics: const NeverScrollableScrollPhysics()