Flutter:如何在 Listview 中删除行之间的空间

Posted

技术标签:

【中文标题】Flutter:如何在 Listview 中删除行之间的空间【英文标题】:Flutter : How to remove space between row in Listview 【发布时间】:2018-10-07 23:15:34 【问题描述】:

我只是在做一些颤振的演示,我喜欢这样做,在列表视图中,我不知道如何删除行之间的空间

我的代码很简单,这个是小部件,我返回到我的布局

Widget _getWidget(BuildContext context) 
return new Material(
    child: new Container(
      padding: EdgeInsets.only(top: 20.0),
      color: Colors.blueGrey[500],
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          _getHeader(context),
          new Expanded(child: getListView())
        ],
      ),
    ),
);

这个是Listview

 ListView getListView() =>
      new ListView.builder(
          itemCount: widgets.length,
          itemBuilder: (BuildContext context, int position) 
            return getRow(position);
          );

这是我使用卡片视图的行

 Widget getRow(int i) 
    return new Padding(padding: new EdgeInsets.all(10.0),
        child: new Card(
          child: new Column(
            children: <Widget>[
              new ListTile(
                title: new Text(
                    "Name : $widgets[i].username"
                ),
                subtitle: new Text(
                    "Decription : You may go now!!"
                ),
              ),
              new ButtonTheme.bar(
                child: new ButtonBar(
                  children: <Widget>[
                    new FlatButton(
                      child: const Text('Accept'),
                      onPressed: ()  /* ... */ ,
                    ),
                    new FlatButton(
                      child: const Text('Reject'),
                      onPressed: ()  /* ... */ ,
                    ),
                  ],
                ),
              ),
            ],
          ),
        )
    );
  

帮帮我。

【问题讨论】:

【参考方案1】:

卡片之间的空格来自 getRow() 方法。

更新你的

new Padding(padding: new EdgeInsets.all(10.0),

new Padding(padding: new EdgeInsets.all(1.0),

看看变化。

如果不想中间有空格,可以直接返回 Card();

【讨论】:

以上是关于Flutter:如何在 Listview 中删除行之间的空间的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Flutter 中删除父 ListView 之外的 InkWell 悬停颜色溢出?

Flutter:在 ListView 中动画项目删除

如何在 Flutter ListView Builder 中删除或管理空间?

Flutter - 删除ListView中项目之间的空间

从 ListView.builder Flutter 中删除项目

如何在 Flutter 中更新 AnimatedList 中的数据