Home > OS >  Shrink font size of TextField on overflow - Flutter
Shrink font size of TextField on overflow - Flutter

Time:09-15

I want the font size of TextField content to shrink when a specific width of TextField is reached. I've tried a few solutions such as calculating the text width using text span but I'm hoping for a more performant solution.

Any help is much appreciated.

CodePudding user response:

The auto_size_text package only works for regular Text widgets.

auto_size_text_field on the other hand will give you what you want.

CodePudding user response:

Best way is using the package auto size text

https://pub.dev/packages/auto_size_text

Check :

AutoSizeText(
  'My Text',
  style: TextStyle(fontSize: 30),
  minFontSize: 18,
  maxLines: 4,
  overflow: TextOverflow.ellipsis,
)

CodePudding user response:

Wrap it with FittedBox widget

FittedBox(
 fit: BoxFit.scaleDown,
 child: Text(...)
 )
  • Related