Change background color of ListTile upon selection in Flutter

前端 未结 12 1780
闹比i
闹比i 2020-12-15 03:10

I\'ve made a ListView in Flutter, but now I have some ListTiles in this ListView that can be selected. Upon selection, I want the back

12条回答
  •  半阙折子戏
    2020-12-15 03:56

    I know that the original question has been answered, but I wanted to add how to set the color of ListTile while the tile is being pressed. The property you are looking for is called highlight color and it can be set by wrapping the ListTile in a Theme widget, like this:

    Theme(
      data: ThemeData(
        highlightColor: Colors.red,
      ),
      child: ListTile(...),
      )
    );
    
    

    Note: if the Theme widget resets the font of text elements inside the ListTile, just set its fontFamily property to the same value You used in other places in your app.

提交回复
热议问题