fazilSizzlers
fazilSizzlers

Reputation: 325

Flutter scaledown font based on container size

How to scaledown font based on container height and width. Tried using Fittedbox it's not working with multiline text.

SizedBox(
            width: MediaQuery.of(context).size.width,
            child: FittedBox(
              fit: BoxFit.contain,
              child: Text(
                widget.model.poem,
                textAlign: TextAlign.justify,
                style: TextStyle(
                    color: Colors.black,
                    fontWeight: FontWeight.w600,
                    fontStyle: FontStyle.normal),
              ),
            ),
          ),

It's shrinking the font as small as shown below. Tried using "Flexible" too not working.

enter image description here

Upvotes: 0

Views: 41

Answers (1)

Ye Lwin Oo
Ye Lwin Oo

Reputation: 556

There ain't many ways to walk around with this issue.

Use auto_size_text plugin

If you wanna automatically resize fonts based on parent widget's width and height, using auto_size_text package is the best option. It's really easy to use and has rich documentation.

Sample Usage:

AutoSizeText(
  'The text to display',
  style: TextStyle(fontSize: 20),
  maxLines: 2,
)

Have fun!

Upvotes: 1

Related Questions