Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to force Text widget to use two line space?

I need to find out a method to force Flutter Text widget to use two text lines space even if the line is only one. For example in the below photo one card is lower than the other one due to the fact that Text widget use only one line space.

enter image description here

Does anyone know some trick to force Text widget to use maxLines space even if only one line is needed?

like image 804
E.Benedos Avatar asked Jan 31 '26 22:01

E.Benedos


2 Answers

Adding minLines to Text is currently an open feature request. You can track it here

For now, a suggested workaround is to use:

str = 'example'; 

Text(
  str + '\n',
  maxLines: 2,
)
like image 125
Sophia Price Avatar answered Feb 02 '26 15:02

Sophia Price


you can use \n to set minimum lines (it is a trick)

this issue is still open Github: Add minLines to Text (flutter issue)

          Text(
            '${product.name}\n\n', //equal minlines: 3
            maxLines: 3,
            overflow: TextOverflow.ellipsis,
            style:
                const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
          ),
like image 31
Mahmoud Salah Eldin-Foxico Avatar answered Feb 02 '26 15:02

Mahmoud Salah Eldin-Foxico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!