How to fit Text to container without using FittedBox

Viewed 760

When using FittedBox, the text size gets very small compared to the text length. I don't want the text to shrink. Instead I want the text to stay the same size and fit only the part that can fit.

Container(
 width: 250,
 child: Text("Data will end with ... instead of shrinking..."),),
3 Answers

I was facing the same challenge, in my Agric app showing weather forecasts to the famers, tried several alternatives but couldn't find a better solution other than using FittedBox. FittedBox has a BoxFit property which align the source within the target box (by default, centering) and, if necessary, scale the source down to ensure that the source fits within the box. This is the same as contain if that would shrink the image, otherwise it is the same as none.

FittedBox(
    fit:BoxFit.scaleDown,
    child: Text("hey, how are you",
    textAlign: TextAlign.start,
    maxLines: 1,
    style: TextStyle(
    fontWeight: FontWeight.normal,
    color: Colors.black.withOpacity(0.4))),
    )
Related