Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ListTileTheme to style ListTile inside ListView?

Tags:

flutter

I'm trying to use ListTileStyle after ListView

ListView(
  ListTileStyle(),
  Children:<widget>[
    ListTile(),
    ListTile(),
    ListTile(),
  ]
),

but not able to use any property of ListTile. Can any one explain how ListTileStyle works.

like image 225
Akram Chauhan Avatar asked May 01 '19 22:05

Akram Chauhan


People also ask

How do you color a list tile in flutter?

Unfortunately, ListTile doesn't have background-color property. Hence, we have to simply wrap the ListTile widget into a Container/Card widget and then we can use its color property. Further, We have to provide SizedBox widget with some height to separate the same colored ListTiles. I hope it will definitely help you.


2 Answers

You should use "ListTileTheme" instead with your ListView as a child, so you can change any property of all the ListTiles you're going to use as childs.

ListTileTheme(
        //properties you want to add
        child: ListView(
          children: <Widget>[//your code],
        ),
      ),
like image 67
Escobar Avatar answered Oct 18 '22 00:10

Escobar


ListView(
  Children:<widget>[
    ListTile(),
    ListTile(),
    ListTileTheme(
      //do sth.
      child:  ListTile(
      ),
    )
  ]
),
like image 31
gan quan Avatar answered Oct 17 '22 23:10

gan quan