skip to Main Content

I want the subtitle of my ListTile to be hidden when it reaches the end of list tile.
What i Get:
enter image description here
What I want:

If i give overflow:TextOverflow.ellipsis to the Text Widget i get this:
enter image description here

Code:

import 'package:flutter/material.dart';


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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GridView.builder(
        itemCount: 19,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            childAspectRatio: 2,
            mainAxisSpacing: 60,
            crossAxisSpacing: 60),
        itemBuilder: (context, index) {
          return ListTile(
            title: Text(
              " title ",
            ),
            subtitle: Text(
              " this is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitle",
              overflow: TextOverflow.ellipsis,
            ),
            tileColor: Colors.grey[200],
          );
        },
      ),
    );
  }
}


2

Answers


  1. can you try maxline property in text

             Text(
                "example",
                maxLines: 3,
                overflow: TextOverflow.ellipsis,
              ),
    
    Login or Signup to reply.
  2. use "maxLines" to give the number of lines for text.

    Like this :

         return ListTile(
            title: Text(
              " title ",
            ),
            subtitle: Text(
              " this is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitlethis is a very long subtitle",
              overflow: TextOverflow.ellipsis,
              maxLines: 3,
            ),
            tileColor: Colors.grey[200],
          );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search