gpt4 book ai didi

flutter - 如何在扩展面板的正文中显示列表?

转载 作者:行者123 更新时间:2023-12-05 06:56:57 25 4
gpt4 key购买 nike

我正在构建垫子扩展面板列表:

Widget _buildAccordion() {
return ExpansionPanelList(
expansionCallback: (int index, bool isExpanded) {
setState(() {
panels[index].isExpanded = !isExpanded;
});
},
children: panels.map<ExpansionPanel>((CalendarDayPanel panel) {
return ExpansionPanel(
canTapOnHeader: true,
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(panel.calendarDay.dateString),
subtitle: Text('${panel.calendarDay.appointmentsNumber} rdv.'),
);
},
body: ListView(children: [
ListTile(title: Text("1st tile")),
ListTile(title: Text("2nd tile"))
]),
isExpanded: panel.isExpanded);
}).toList(),
);
}

我希望每个 ExpansionPanel 的主体显示一个图 block 列表。但是,当我尝试展开面板时出现渲染错误。如果我使用一个简单的文本小部件而不是主体中的 ListView,它工作正常。

我应该怎么做才能在扩展面板的正文中显示列表?

记录的完整错误消息是:

RenderBox was not laid out: RenderRepaintBoundary#e926crelayoutBoundary=up24 NEEDS-PAINT

更新

将正文更改为:

body: ListView(
shrinkWrap: true,
children: [
ListTile(title: Text("1st tile")),
ListTile(title: Text("2nd tile"))
],
),

仍在努力掌握这里的底层逻辑。

最佳答案

Widget _buildAccordion() {
return ExpansionPanelList(
expansionCallback: (int index, bool isExpanded) {
setState(() {
panels[index].isExpanded = !isExpanded;
});
},
children: panels.map<ExpansionPanel>((CalendarDayPanel panel) {
return ExpansionPanel(
canTapOnHeader: true,
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(panel.calendarDay.dateString),
subtitle: Text('${panel.calendarDay.appointmentsNumber} rdv.'),
);
},
body: Column(
children: <Widget>[
Expanded(
child: ListView(children: [
ListTile(title: Text("1st tile")),
ListTile(title: Text("2nd tile"))
]),
),
],
),
isExpanded: panel.isExpanded);
}).toList(),
);
}

上面的更改.. 通过扩展和按列扩展包装 ListView。

关于flutter - 如何在扩展面板的正文中显示列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65002453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com