auto_size_text
auto_size_text copied to clipboard
AutoSizeGroupBuilder widget would be a good convenience feature
Every time someone is new to AutoSizeText, they initially make this mistake:
class MyWidget extends StatelessWidget {
final _autoSizeGroup = AutoSizeGroup();
@override Widget build() {
return Column(
children: [
AutoSizeText('hello', autoSizeGroup: _autoSizeGroup),
AutoSizeText('goodbye', autoSizeGroup: _autoSizeGroup),
],
);
}
}
The non-obvious mistake being that the AutoSizeGroup will keep being reconstructed any time the widget rebuilds, and lose its state, which can cause flickering and performance issues.
The addition of a standard AutoSizeGroupBuilder to capture the AutoSizeGroup in its own stateful widget would make it much simpler to use it correctly, like:
class MyWidget extends StatelessWidget {
@override Widget build() {
return AutoSizeGroupBuilder(
builder: (_, autoSizeGroup) => Column(
children: [
AutoSizeText('hello', autoSizeGroup: autoSizeGroup),
AutoSizeText('goodbye', autoSizeGroup: autoSizeGroup),
],
),
);
}
}
I think that's a great idea 👍