İçeriğe geç / Skip to content / Zum Inhalt

Flutter ListTile: Usage and the Trailing Row Error

Ahmet Balaman

5 min read

FlutterListTileListViewRowmainAxisSizeMaterial
Flutter ListTile: Usage and the Trailing Row Error

ListTile is the Material widget for a single row in a list: an optional leading widget, one to three lines of text, and an optional trailing widget. Settings screens, contact lists, order lists and menus are mostly ListTiles inside a ListView. It is also the source of one of the most searched Flutter errors: putting a Row in trailing and getting an assertion that says the trailing widget "consumes the entire tile width". This post covers normal usage first, then that error, why it happens and three ways to fix it.

Basic Usage

ListTile(
  leading: const CircleAvatar(child: Icon(Icons.person)),
  title: const Text('Alex Morgan'),
  subtitle: const Text('Last seen today'),
  trailing: const Icon(Icons.chevron_right),
  onTap: () => debugPrint('Tapped'),
)

ListTile needs a Material ancestor, which a Scaffold already provides. Inside a ListView the tile gets the full width and a height that depends on its content.

Important Properties

Property What it does
leading Widget at the start, usually an icon or avatar
title Main text
subtitle Second line under the title
trailing Widget at the end: an icon, a switch, a menu button
onTap / onLongPress Makes the tile tappable and adds the ink splash
isThreeLine Allows a three-line subtitle; adjusts height
dense Smaller height and text for compact lists
contentPadding Inner padding; defaults are set by the theme
tileColor / selectedTileColor Background color, normal and selected
selected Marks the tile as selected and tints text and icons
enabled Set to false to dim and disable taps
shape Shape of the tile and its ink splash, such as a rounded rectangle
visualDensity Fine-tunes height without changing the layout rules
titleAlignment Vertical alignment of leading and trailing relative to the text

The Trailing Row Error

You want two actions at the end of a tile, so you write this:

// Throws an assertion error
ListTile(
  title: const Text('Order #1042'),
  trailing: Row(
    children: const [
      Icon(Icons.edit),
      Icon(Icons.delete),
    ],
  ),
)

The framework stops with a failed assertion in list_tile.dart, 'tileWidth != trailingSize.width', and a message that starts with "ListTile's trailing widget consumes the entire tile width". The same rule exists for leading.

Why It Happens

A Row has mainAxisSize: MainAxisSize.max by default, so it tries to take all the width it is offered. ListTile hands trailing a wide constraint, the Row fills it, and the tile is left with no room for the title. The assertion is there to tell you the layout cannot work, instead of drawing a broken tile. If the difference between max and min is new to you, the mainAxisSize guide explains it in detail.

Fix 1: Row with MainAxisSize.min

The shortest fix. The Row is as wide as its children and no wider:

ListTile(
  title: const Text('Order #1042'),
  trailing: Row(
    mainAxisSize: MainAxisSize.min,
    children: const [
      Icon(Icons.edit),
      SizedBox(width: 8),
      Icon(Icons.delete),
    ],
  ),
)

Fix 2: A SizedBox with a Fixed Width

When the trailing area should have a stable width, for example so that several rows line up, give it one:

ListTile(
  title: const Text('Order #1042'),
  trailing: SizedBox(
    width: 96,
    child: Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        IconButton(icon: const Icon(Icons.edit), onPressed: () {}),
        IconButton(icon: const Icon(Icons.delete), onPressed: () {}),
      ],
    ),
  ),
)

An IconButton is 48 logical pixels wide by default, so two of them need 96.

Fix 3: Use One Action and a Menu

Two or more actions in a trailing slot make small screens crowded. A single PopupMenuButton takes one icon of space and holds as many actions as you need:

ListTile(
  title: const Text('Order #1042'),
  trailing: PopupMenuButton<String>(
    onSelected: (value) => debugPrint(value),
    itemBuilder: (context) => const [
      PopupMenuItem(value: 'edit', child: Text('Edit')),
      PopupMenuItem(value: 'delete', child: Text('Delete')),
    ],
  ),
)

Other Common Mistakes

ListTile inside a Row

A ListTile wants a bounded width. Directly inside a Row it has none, and you get an error about unbounded width. Wrap it in Expanded:

Row(
  children: const [
    Expanded(child: ListTile(title: Text('Name'))),
    Icon(Icons.star),
  ],
)

See the Expanded guide for why this works.

A colored Container hides the ink splash

If you wrap a ListTile in a Container(color: ...), the background paints over the Material layer and the tap splash is hidden behind it. Use the tile's own tileColor, or wrap in Material(color: ...):

ListTile(
  tileColor: Colors.grey.shade100,
  title: const Text('Settings'),
  onTap: () {},
)

Long text overflows

Without limits, a very long title makes the tile tall. Limit it explicitly:

ListTile(
  title: const Text(
    'A very long title that should not take over the screen',
    maxLines: 1,
    overflow: TextOverflow.ellipsis,
  ),
)

Subtitle with more than two lines

If the subtitle needs three lines, set isThreeLine: true. Otherwise the text may be clipped or the layout can look cramped.

Mini Scenario: An Order List

class OrderList extends StatelessWidget {
  const OrderList({super.key});

  @override
  Widget build(BuildContext context) {
    final orders = List.generate(5, (i) => 'Order #${1040 + i}');

    return ListView.separated(
      itemCount: orders.length,
      separatorBuilder: (_, __) => const Divider(height: 1),
      itemBuilder: (context, index) {
        return ListTile(
          leading: const Icon(Icons.receipt_long),
          title: Text(orders[index]),
          subtitle: const Text('Waiting for payment'),
          trailing: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              IconButton(
                icon: const Icon(Icons.edit),
                onPressed: () {},
              ),
              IconButton(
                icon: const Icon(Icons.delete),
                onPressed: () {},
              ),
            ],
          ),
          onTap: () {},
        );
      },
    );
  }
}

For long or dynamic lists, ListView.builder and ListView.separated only build the visible rows. More on that in the ListView guide.

When Not to Use ListTile

ListTile is built for a standard leading, text, trailing layout. If the row needs a picture on top, several text blocks, a progress bar or a custom arrangement, build the row yourself with Row, Column and Expanded, and wrap it in InkWell for taps. Fighting ListTile's fixed layout costs more than writing the row.

Frequently Asked Questions

Why does my ListTile throw "trailing widget consumes the entire tile width"?

Because the trailing widget, usually a Row, expands to the full available width. Give the Row mainAxisSize: MainAxisSize.min, or constrain the trailing widget with a SizedBox that has a fixed width.

Can I put two icons in a ListTile's trailing?

Yes. Use a Row with mainAxisSize: MainAxisSize.min. If the screen is narrow, consider a PopupMenuButton instead.

How do I make a ListTile tappable?

Set onTap. The tile then reacts to touches and shows the ink splash. Use onLongPress for a long press.

Why doesn't the tap splash show on my ListTile?

A parent with its own background color, such as Container(color: ...), usually covers it. Use tileColor or a Material parent instead.

How do I align the trailing widget to the top?

Use the titleAlignment property, for example ListTileTitleAlignment.top. If your Flutter version does not have it, build the row with Row and CrossAxisAlignment.start.

Source

Comments