0

I have multi-line text inside an Expanded. But instead of showing ellipsis (as specified), it clips the text at the bottom.

This is because it only truncates after the specified maxLines. But depending on my device size the amount of lines that fit in the available space will vary. I need the text to be as long as possible before it truncates.

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

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
        child: SizedBox(
          width: 100,
          height: 100,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Expanded(
                child: Text(
                  'This is some really long multiline text This is some really long multiline text This is some really long multiline text.',
                  overflow: TextOverflow.ellipsis,
                  maxLines: 20,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
JakesMD
  • 1,646
  • 2
  • 15
  • 35
  • its work as well. what did you expect? – pmatatias Aug 08 '23 at 17:04
  • if you set the `overflow` property, it will clip the text. Read here https://api.flutter.dev/flutter/painting/TextOverflow.html – pmatatias Aug 08 '23 at 17:05
  • I should show ellipsis as specified. But it clips the text. – JakesMD Aug 08 '23 at 17:11
  • This is because you set `maxLines` to 20. According to to [documentation](https://api.flutter.dev/flutter/widgets/Text/maxLines.html): "If the text exceeds the given number of lines, it will be truncated according to overflow.". In your case the text does not exceed 20 lines. With `maxLines` set to 3 for example it show the ellipsis. – Peter Koltai Aug 08 '23 at 20:04
  • Thanks. But because it's an Expanded widget the amount of lines that fit in the space will vary from device to device. I want to fit as many in a possible before it truncates. – JakesMD Aug 09 '23 at 04:21

0 Answers0