无法在 Flutter 中滚动 ListView

Unable to scroll ListView in Flutter

我是 Flutter 的新手,目前正在从事一个需要可滚动列的项目。所以我使用了ListView。 CollapseTile 是一个重构的小部件。

代码如下:

Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
          children: <Widget>[
            ListView(
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                children: <Widget>[
                  SizedBox(height: 20.0),
                  CollapseTile(
                    text: 'Skin',
                    children: <Widget>[
                      ListView.builder(
                          shrinkWrap: true,
                          physics: AlwaysScrollableScrollPhysics(),
                          itemCount: data['skin'].length,
                          itemBuilder: (BuildContext context, int index) {
                            print(_selectedSkin);
                            return CheckboxListTile(
                              title: Text(data['skin'][index]['name']),
                              value: _selectedSkin
                                  .contains(data['skin'][index]['name']),
                              secondary: Image(
                                image: AssetImage(
                                    'images/${skinImageName[index]}'),
                              ),
                              onChanged: (bool selected) {
                                _onSelected(
                                    selected, data['skin'][index]['name']);
                              },
                            );
                          })
                    ],
                  ),
                  CollapseTile(
                    text: 'Teeth',
                    children: <Widget>[],
                  ),
                  CollapseTile(
                    text: 'Mouth',
                    children: <Widget>[],
                  ),
                  CollapseTile(
                    text: 'Eye',
                    children: <Widget>[],
                  ),
                  CollapseTile(
                    text: 'Hair',
                    children: <Widget>[],
                  ),
                  CollapseTile(
                    text: 'Nails',
                    children: <Widget>[],
                  ),
                ],
              ),
            ),
          ],
        );
  }

但是ListView不滚动,RenderFlex溢出。

ListView.

中添加 SingleChildScrollView 并添加物理作为 NeverScrollableScrollPhysics
 Scaffold(
  body: SingleChildScrollView( 
    child: Column(
      children: <Widget>[
    ListView(
    scrollDirection: Axis.vertical,
      physics: NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      children: <Widget>[
        SizedBox(height: 20.0),
        CollapseTile(
          text: 'Skin',
          children: <Widget>[
            ListView.builder(
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                itemCount: data['skin'].length,
                itemBuilder: (BuildContext context, int index) {
                  print(_selectedSkin);
                  return CheckboxListTile(
                    title: Text(data['skin'][index]['name']),
                    value: _selectedSkin
                        .contains(data['skin'][index]['name']),
                    secondary: Image(
                      image: AssetImage(
                          'images/${skinImageName[index]}'),
                    ),
                    onChanged: (bool selected) {
                      _onSelected(
                          selected, data['skin'][index]['name']);
                    },
                  );
                })
          ],
        ),
        CollapseTile(
          text: 'Teeth',
          children: <Widget>[],
        ),
        CollapseTile(
          text: 'Mouth',
          children: <Widget>[],
        ),
        CollapseTile(
          text: 'Eye',
          children: <Widget>[],
        ),
        CollapseTile(
          text: 'Hair',
          children: <Widget>[],
        ),
        CollapseTile(
          text: 'Nails',
          children: <Widget>[],
        ),
      ],
    ),
),
  ),
],
);