I have a fixed-size box that I need to pass the height value.
Inside the box, I have a Text widget that could overflow so I need to set the 'maxLines' 2. However, because the box height is fixed, the Text widget will not take 2 lines.
I can pass a larger value to the height of the box, but it doesn't look nice if the Text widget only takes up 1 line.
It would be nice if I can calculate the total pixel of the Text widget then work out how many lines the Text widget is needed by comparing it with the width of the fixed-size box.
SizedBox(
child: Text(
title,
style: Theme.of(context).textTheme.headline6,
maxLines: 2,
),
width: 300,
height: 60,
),
for example
height: Theme.of(context).textTheme.headline6.fontSize * title.length > 300? 72 : 60