Remove space top and bottom ListTile flutter

耗尽温柔 提交于 2020-08-24 06:02:32

问题


I need help, please. How to remove the space top and bottom from ListTile?

My Code is:

             child: Column(
                children: <Widget>[
                  ListTile(
                    contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
                    title: Text(
                      'Home',
                      style: TextStyle(fontSize: 15.0),
                    ),
                  ),
                  ListTile(
                    contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
                    title: Text(
                      'Audio',
                      style:
                          TextStyle(fontSize: 15.0, color: Colors.black45),
                    ),
                  ),),

Screenshot

Thanks!. Sorry for my bad English


回答1:


With ListTile it is not possible. Some modification are possible with the help of ListTileTheme like color and their is also option of modifying padding but only work for left and right padding. So better is to create your own custom tile like @santosh showed in his answer. You can also use SizedBox but it can result tragic output.




回答2:


In your code put property dense= true in side the list tile

       ListTile(
                dense:true,
                contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
                title: Text(
                  'Home',
                  style: TextStyle(fontSize: 15.0),
                ),
              ),

Hope it helps!




回答3:


Try this

              child: Column(
                children: <Widget>[
                    Text(
                      'Home',
                      style: TextStyle(fontSize: 15.0),
                    ),
                    Text(
                      'Audio',
                      style:
                          TextStyle(fontSize: 15.0, color: Colors.black45),
                    ),
                 ),)



回答4:


Implementation this one dense:true, in your ListTile Properties, The dense parameter makes the text smaller and packs everything together.

You can change how much the content is inset on the left and right (but not the top or bottom) by setting the contentPadding. The default is 16.0 but here we will set to 0.0:

 ListTile(
   contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 
    0.0),
   dense:true,
   title: Text("Your title"),
   subtitle: Text("subtitle",
    style: TextStyle(fontSize: 14.0),),
 );



回答5:


You can use the visualDensity property to reduce the space.

ListTile(
    visualDensity: VisualDensity(horizontal: 0, vertical: -4),
    title: Text("xyz")
);

The visualDensity value can be changed from -4.0 to 4.0. Lower the value, more compact the view.

P.S. This solution is similar to a different question

This question is about the top/bottom spacing. But the other question is about gap between leading and title




回答6:


For me Padding widget worked in place of ListTile.padding variable can be updated as per your requirements for a ListItem.

Padding(
        padding: const EdgeInsets.only(left : 8.0 , right 8.0),
        child: Text("List Item Text",
            style: Theme.of(context).textTheme.body1))


来源:https://stackoverflow.com/questions/55265313/remove-space-top-and-bottom-listtile-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!