Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing two trailing icons in ListTile

I want to place two icons, side by side on the "trailing" side of a ListTile. I tried adding a Row widget with the two icons inside, but it completely messed up the layout of the entire ListTile, making it unusable. Is there any way to expand the space allocated for the trailing part?

Here's the code:

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Flutter'),
        ),
        body: ListView(
      children: <Widget>[
        ListTile(
          leading: Icon(Icons.play_arrow,),
          title: Text("This is a title"),
          subtitle: Text("This is subtitle"),
          trailing: Row(          
            children: <Widget>[
            Icon(Icons.flight),
            Icon(Icons.flight_land)
          ]),
        )
      ]
    ),
      ),
    );
  }
}

This is how it looks like:

like image 608
avishorp Avatar asked Feb 06 '19 07:02

avishorp


People also ask

What is trailing in ListTile flutter?

trailing. A widget to display after the title. Typically an Icon widget. To show right-aligned metadata (assuming left-to-right reading order; left-aligned for right-to-left reading order), consider using a Row with CrossAxisAlignment.

Is a 3 Line a flutter?

By default, the ListTile in flutter can display only 2 lines. The Title and the SubTitle. In case there is a third line of text to be displayed, the isThreeLine is set to true and can allow another line to be present. The subtitle will be taking care of giving the 3rd line of text.


3 Answers

Adding mainAxisSize: MainAxisSize.min to the Row() instance fixes the issue.

like image 64
avishorp Avatar answered Oct 20 '22 18:10

avishorp


You can simply use Wrap in trailing

ListTile(
  title: Text("This is my ListTile"),
  trailing: Wrap(
    spacing: 12, // space between two icons
    children: <Widget>[
      Icon(Icons.call), // icon-1
      Icon(Icons.message), // icon-2
    ],
  ),
)

enter image description here

like image 27
CopsOnRoad Avatar answered Oct 20 '22 18:10

CopsOnRoad


Try this code. I think this is working correctly:

trailing: FittedBox(
          fit: BoxFit.fill,
          child: Row(
          children: <Widget>[
            Icon(Icons.flight),
            Icon(Icons.flight_land),
          ],
          ),
        ),
like image 25
TipVisor Avatar answered Oct 20 '22 17:10

TipVisor