Search code examples
fluttertextmultiline

Always display text on two lines


I have Text:

Text(
  "My long ... long ... text",
  style: const TextStyle(overflow: TextOverflow.ellipsis),
  maxLines: 2,
),

In case text is long, it will be displayed on two lines only. My question is: is it possible to, in case of short text, to take the same space as this long text (as two lines)? I need to calculate the height and therefore I need to take into account two lines everytime. Also in case there is only short text. Thank you for your advise.


Solution

  • Add \n to create a new line at the end.

     Text(
       '${myString}\n'
     ),