Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter : How to remove space between row in Listview

I am just doing some demos of flutter, I love to do it, In listview, I cant find out that how to remove space between rows

enter image description here

my code is pretty simple, This one is Widget which I return to my layout

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

}

This one is Listview

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

This one is row which i use card view

 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: () { /* ... */ },
                    ),
                  ],
                ),
              ),
            ],
          ),
        )
    );
  }

Help Me.

like image 910
Mohit Suthar Avatar asked Apr 27 '18 06:04

Mohit Suthar


People also ask

How do you remove space between ListView items in Flutter?

Solution: Use visualDensity property instead within the ListTile .

How do you remove spaces between rows in Flutter?

you are using expanded widget inside row so that both the widget try to get same width and also try to cover whole width possible. so that, if you want to remove space between row widget then remove expanded widget and play with MainAxisAlignment property of Row to arrange or manage the space.

What is ListView separator Flutter?

ListView. separated creates a fixed-length, scrollable , linear array of list “items” separated by list item “separators”. The itemBuilder callback is called whenever there are indices ≥ 0 and< itemCount .


1 Answers

The spaces that you are getting between cards is from getRow() method.

Just update your

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

to

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

and see the change.

If you don't want any spaces in between, you can directly return Card();

like image 81
Dhrumil Shah - dhuma1981 Avatar answered Oct 01 '22 23:10

Dhrumil Shah - dhuma1981