simc / auto_size_text

Flutter widget that automatically resizes text to fit perfectly within its bounds.
https://pub.dev/packages/auto_size_text
MIT License
2.06k stars 241 forks source link

Add an optional wrapTextWidget property #90

Closed emagnier closed 3 years ago

emagnier commented 3 years ago

This PR adds the ability to wrap the text by any other widget (like a Container), without wrapping the widget specified in the overflowReplacement parameter.

This is especially useful when you want to add extra padding on your text, but not on the overflow replacement widget.

For example:

AutoSizeText(
  'XXXXX', // Extra padding of 5px is added around this text
  style: TextStyle(fontSize: 20),
  wrapTextWidget: (_, text) => Container(
    padding: EdgeInsets.all(5),
    child: text,
  ),
  overflowReplacement: Text('*'), // No padding is added arount this replacement text
),
emagnier commented 3 years ago

Maybe the wrapTextWidget could have a better name (if you have better ideas)?

Just to give more context in a "real world", I'm using overflowReplacement with the marquee flutter package. So when the text is too long, it scrolls horizontally and automatically.

And since this replacement widget needs an extra width (to add fading edges), this new parameters allows to add padding to the original text widget, to offset the text alignment when the replacement widget isn't necessary.

Apr-08-2021 15-10-17

esDotDev commented 3 years ago

I think this can be handled by my textBuilder PR that is ready to land: https://github.com/leisim/auto_size_text/pull/85

emagnier commented 3 years ago

Indeed 👍

I'm looking forward to seeing it merged, thanks for your addition!