text_wrap_auto_size 1.0.0+1 text_wrap_auto_size: ^1.0.0+1 copied to clipboard
Wraps text and auto sizes it dynamically with respect to the given space.
text_wrap_auto_size #
Wraps text and auto sizes it with respect to the given space.
Changing the text or changing the boundaries triggers a new layout cycle, thus adapting the text size dynamically.
Requirements #
The widget requires a given width and height.
It will throw an Exception, if it reveives an unbound (infinite) width or height.
More about Flutter contraints here.
Usage #
Generally, the TextStyle
is respected.
final style = TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red);
final text = Text('text', style: style);
TextWrapAutoSize(text);
Define width and height.
SizedBox(
width:250,
height:250,
child: TextWrapAutoSize(Text('text'))
);
In some case, width and height can be determined by wrapping the widget in Expanded
.
Expanded(
child: TextWrapAutoSize(Text('text'))
);
Use it as the Scaffold
's body:
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: TextWrapAutoSize(Text('text')),
),
);
}
Issues and Background #
The package follows the most simple apporach I could think of. There might be a more efficient approach.
Internally, the widget performs a binary-search for the optimal font size and renders the text multiple times in its own render-tree.
The code measuring the widget size can be found in the Flutter docs.
Open an issue on Github.