ListView.builder在列中不起作用

时间:2019-05-03 15:00:22

标签: android dart flutter flutter-layout

ListView.builder在center()旁边工作正常。但是当我将中心更改为列ListView.builder时不会滚动。

return Column(
          children: <Widget>[
            ListView.builder(
            padding: const EdgeInsets.only(bottom: 20.0),
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            itemCount: snapshot.data.length,
            itemBuilder: (_, index) {
              return Center(
                child: CheckboxListTile(
                    value: names
                        .contains(snapshot.data[index].data["Name"]),
                    title: Text(snapshot.data[index].data["Name"]),
                    onChanged: (bool selected) {
                      //markMember(snapshot.data[index].data["Name"]);
                      _onCategorySelected(
                          selected,       snapshot.data[index].data["Name"],snapshot.data[index].data["IndexNo"]);
                    }),
              );

            }),
          ],

        );

我想在ListView下添加另一个FloatingActionButton。

2 个答案:

答案 0 :(得分:0)

您可以将floatingActionButton的{​​{1}}参数设置为使用Scaffold,因此您无需为此将FloatingActionButton放在ListView内。 / p>

示例

Column

答案 1 :(得分:0)

如果您希望在listview小部件内滚动时column中滚动,请用ListView.builder小部件包装Expanded小部件。

return Column(
          children: <Widget>[
         Expanded(
           child:  ListView.builder(
            padding: const EdgeInsets.only(bottom: 20.0),
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            itemCount: snapshot.data.length,
            itemBuilder: (_, index) {
              return Center(
                child: CheckboxListTile(
                    value: names
                        .contains(snapshot.data[index].data["Name"]),
                    title: Text(snapshot.data[index].data["Name"]),
                    onChanged: (bool selected) {
                      //markMember(snapshot.data[index].data["Name"]);
                      _onCategorySelected(
                          selected,
snapshot.data[index].data["Name"],snapshot.data[index].data["IndexNo"]);
                    }),
              );

            })),
          ],

        );