flutter 如何在扩展面板的主体中显示列表?

70gysomp  于 2023-06-07  发布在  Flutter
关注(0)|答案(2)|浏览(171)

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

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的主体显示一个瓷砖列表。然而,我有渲染错误,当我试图扩大面板。如果不是在正文中使用ListView,我使用一个简单的文本小部件,它工作得很好。
要在扩展面板的主体中显示列表,我应该怎么做?
记录的完整错误消息为:
RenderBox没有布局:RenderRepaintBoundary#e926c relayoutBoundary=up24需要油漆

更新

主体变更为:

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

我还在试图理解其中的逻辑。

sq1bmfud

sq1bmfud1#

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换行。

au9on6nz

au9on6nz2#

尝试将以下内容添加到ListView.builder:
shrinkWrap:true,
physics:const NeverScrollableScrollPhysics(),
查看更新的代码:

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(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: [
              ListTile(title: Text("1st tile")),
              ListTile(title: Text("2nd tile"))
            ]),
            isExpanded: panel.isExpanded);
      }).toList(),
    );
  }

相关问题