【问题标题】:ListView.builder is not working in side a columnListView.builder 不在列中工作
【发布时间】:2019-05-03 15:00:21
【问题描述】:

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。

【问题讨论】:

    标签: android dart flutter flutter-layout


    【解决方案1】:

    您可以将ScaffoldfloatingActionButton 参数设置为使用FloatingActionButton,因此您无需为此将ListView 放入Column

    示例

    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: _openFilePicker,
        child: Icon(Icons.attach_file),
      ),
      body: // Your ListView goes here.
    );
    

    【讨论】:

    • 谢谢。我是这样做的。我是 Flutter 新手。
    • 不客气的朋友。我也是,我也是新手。 :D
    【解决方案2】:

    如果您想在listview 位于column 小部件内时启用滚动,则使用Expanded 小部件包装您的ListView.builder 小部件。

    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"]);
                        }),
                  );
    
                })),
              ],
    
            );
    

    【讨论】:

      猜你喜欢
      • 2018-12-02
      • 2021-10-01
      • 2019-11-03
      • 2021-09-19
      • 2022-07-25
      • 2021-11-10
      • 2020-09-25
      • 2023-03-13
      • 2021-10-06
      相关资源
      最近更新 更多