auto_size_text icon indicating copy to clipboard operation
auto_size_text copied to clipboard

AutoSizeGroupBuilder widget would be a good convenience feature

Open ravenblackx opened this issue 4 years ago • 1 comments

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),
        ],
      ),
    );
  }
}

ravenblackx avatar Mar 04 '21 22:03 ravenblackx

I think that's a great idea 👍

simc avatar Mar 04 '21 23:03 simc