ListTile
ListTile
is a common and versatile widget in Flutter that's used to create individual items or tiles in a list. It's typically used within a ListView
or ListView.builder
to display a list of items, such as a menu, settings, or any other list-based user interface. ListTile
simplifies the creation of individual list items by providing a pre-designed layout that includes text, icons, and other common elements. Here's an overview of the ListTile
widget:
Key Properties and Features:
leading
: Theleading
property is used to specify a widget, usually anIcon
orImage
, that appears at the beginning of theListTile
. This is typically used for displaying an icon or avatar.title
: Thetitle
property is used to specify the primary content of theListTile
. It's usually aText
widget but can be any widget.subtitle
: Thesubtitle
property is used to provide additional descriptive text below thetitle
. It's often used for secondary information.trailing
: Thetrailing
property is used to specify a widget that appears at the end of theListTile
. Similar toleading
, it's often used for icons or buttons, such as a delete button or a checkbox.onTap
: TheonTap
property allows you to specify a function that will be called when theListTile
is tapped, making it interactive. IfonTap
is null, theListTile
won't respond to taps.isThreeLine
: Whentrue
, theListTile
is optimized for a layout with a longtitle
andsubtitle
. It increases the spacing between the title and subtitle.dense
: Whentrue
, theListTile
has reduced padding and smaller fonts, making it more compact.selected
: Indicates whether theListTile
is in a selected state, which can be useful for creating selectable lists.
Example Usage:
Here's a simple example of using ListTile
within a ListView
:
In the code above, we've created a ListView
with two ListTile
items. Each ListTile
consists of an Icon
, a title
, and an onTap
function to define what happens when the item is tapped. You can customize the appearance and behavior of ListTile
items to suit your specific use case.
ListTile
is a versatile widget, and you can use it to create various types of lists, menus, or settings screens in your Flutter applications.
Last updated