Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter how to use ListTile Threeline

Tags:

flutter

dart

Flutter when I used ListTile ThreeLines, I don't know how to use ThreeLine

    import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('ddd'),
        ),
        body:Container(
        child: Column(
          children: <Widget>[
            ListTile(
              isThreeLine: true,
              leading: Icon(Icons.event_note),
              title: Text('Title 1'),
              // subtitle: Text('Title2'),
              subtitle: Column(

                children: <Widget>[
                  Text('Titile2'),
                  Text('Title 3'),
                  Text('Title 4'),
                  Text('and so on')
                ],
              ),

            )
          ],
        ),
      ) ,
      ),

    );
  }
}

When i delete isThreeLines, the code is Ok

ListTile

Thanks

like image 770
zhiyuanbuqi Avatar asked Nov 29 '18 12:11

zhiyuanbuqi


People also ask

How do you use a row in a ListTile flutter?

Just give it some constraints (eg. by wrapping in a SizedBox with a width ) or, if you want to take it as much space as possible, just wrap each ListTile with a Flex widget such as Flexible or Expanded if you want to share space evenly with all tiles on that Column .

How do you give a border radius to a ListTile in flutter?

To add or change the ListTile border color, add the shape parameter with RoundedRectangleBorder() inside the ListTile widget. Inside the RoundedRectangleBorder widget, add the side property and assign the BorderSide(width: 2, color: Colors. amberAccent).

How do you add a ListTile in flutter?

To add the divider between ListTile items, add the ListView widget. Inside ListView , add the ListTile. divideTiles with the tiles property and a list of ListTiles.


2 Answers

As from the docs:

The value of subtitle, which is optional, will occupy the space allocated for an additional line of text, or two lines if isThreeLine is true.

It basically means the subtitle of the ListTile is given more space to have text which is more than one line in length:

ThreeLine Demo

like image 197
soupjake Avatar answered Sep 20 '22 06:09

soupjake


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. It is expected that, if the isThreeLine is set to true, the subtitle should be non-null. Anything after "\n" inside subtitle will come in next line

ListTile(
              title: Text("First Line",
              style: TextStyle(fontWeight: FontWeight.bold)),
              subtitle: Text("Second One Text "\nThis is Line Third Text"),
              isThreeLine: true,
              trailing: Row(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  GestureDetector(
                    child: Icon(Icons.delete,color: Colors.red,),
                    onTap: () {
                    },
                  ),
                ],
              ),
              onTap: (){},
            )
like image 30
Kumar Krati Gupta Avatar answered Sep 20 '22 06:09

Kumar Krati Gupta