Flutter: ListTile with multiple Trailing Icon Buttons

Updated: August 27, 2023 By: A Goodman 2 comments

There might be cases where you want to add multiple trailing icon buttons to a ListTIle widget. Many Flutter developers will get a solution in seconds: using a Row widget and placing some icon buttons inside it, like this:

ListTile(
            title: Text('The Title'),
            subtitle: Text('The Subtitle'),
            trailing: Row(
              children: [
                IconButton(onPressed: () {}, icon: Icon(Icons.favorite)),
                IconButton(onPressed: () {}, icon: Icon(Icons.edit)),
                IconButton(onPressed: () {}, icon: Icon(Icons.delete)),
              ],
            ),
          )

Unfortunately, if do so, you may run into the following error:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═══
The following assertion was thrown during performLayout():
Trailing widget consumes entire tile width. Please use a sized widget, or consider replacing
ListTile with a custom widget

To fix this issue, we have more than one option:

1. Set the mainAxisSize property of the Row widget to MainAxisSize.min:

ListTile(
            title: const Text('The Title'),
            subtitle: const Text('The Subtitle'),
            trailing: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                IconButton(onPressed: () {}, icon: const Icon(Icons.favorite)),
                IconButton(onPressed: () {}, icon: const Icon(Icons.edit)),
                IconButton(onPressed: () {}, icon: const Icon(Icons.delete)),
              ],
            ),
          )

And it works as expected:

2. The second option is to wrap the Row widget within a SizedBox or a Container widget with a fixed width, like this:

 ListTile(
            title: const Text('The Title'),
            subtitle: const Text('The Subtitle'),
            trailing: SizedBox(
              width: 150,
              child: Row(
                children: [
                  IconButton(onPressed: () {}, icon: const Icon(Icons.favorite)),
                  IconButton(onPressed: () {}, icon: const Icon(Icons.edit)),
                  IconButton(onPressed: () {}, icon: const Icon(Icons.delete)),
                ],
              ),
            ),
          )

And it works just fine, too.

Continue learning more new and exciting stuff in Flutter by having a look at the following:

You can also check out our Flutter category page or Dart category page for the latest tutorials and examples.

Subscribe
Notify of
guest
2 Comments
Inline Feedbacks
View all comments
JELLO
JELLO
1 year ago

JELLO WORLD

jonas
jonas
2 years ago

Very helpful, thanks!

Related Articles