Flutter

Resize Text automatically

By August 4, 2020 November 28th, 2020 No Comments

One of the most common scenarios I find in Flutter (like in any other Apps). It is to layout properly the text with different font sizes in all types of screens, all sizes, density pixels, ratios, etc.

You have your layout ready and the beautiful text displayed:

but then, you try it in another device and it looks horribly?

The solution is simple, implement an automatically/dynamically resize text. replace your Text with AutoSizeText.

Install the package:

auto_size_text: ^2.1.0

you can run a replaceAll command on your IDE and replace Text by AutoSizeText. Most of the cases will work.

With AutoSizeText the text will be resized automatically to fit the boundaries of the container. No more calculations for fonts!

Also, it is extremely configurable.

minFontSize: The minimum size of font it will reach.

maxFontSize: The minimum size of font it will reach.

maxLines: Same as Text.

style: Same as Text.

textAlign: Same as Text.

 

Just using this strategy to auto resize text. Your texts will never be cut again.

Ernie

Author Ernie

More posts by Ernie