user6274128
user6274128

Reputation:

Flutter AutoResizeTextView, setting high fontSize overflows

In Android, we can use AutoResizeTextView and give it any text size of our choice, it will not flow out of its constraints, I was looking for similar solution in Flutter.

I tried following,

Container(
  color: Colors.blue,
  constraints: BoxConstraints(maxHeight: 200.0, minWidth: 600.0),
  child: Text("8", style: TextStyle(fontSize: 400.0)),
);

Here is the ugly output. So, how can I force the Text to always stay inside the Container no matter how much fontSize is given to it

enter image description here

Upvotes: 0

Views: 72

Answers (1)

user6274128
user6274128

Reputation:

Thanks to pskink,

I need to wrap the Text inside FittedBox which is further wrapped inside a Container. Here is the solution.

Container(
  color: Colors.blue,
  constraints: BoxConstraints(maxHeight: 200.0, minWidth: 600.0),
  child: FittedBox(child: Text("8", style: TextStyle(fontSize: 400.0))),
);

Upvotes: 1

Related Questions