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 240 forks source link

AutoSizeText doesn't work on build, only after setState. #123

Open burekas7 opened 2 years ago

burekas7 commented 2 years ago

Steps to Reproduce Hi, I'm using AutoSizeText on web. After build (Refresh page, hot reload, restart etc...) AutoSizeText doesn't resize the text according to the sizes. It does work after doing 'setState' operation.

What coukd be the reason?

Thanks.

Version

gentunian commented 1 year ago

EDIT: I got confused with AutoSizeTextField package, and it looks like it's a simulator issue... not sure yet.

I'm experimenting the contrary. That is, when a widget is build and you don't rebuild, the autosize works OK.

But if you setState() and rebuild the widget, autosize won't work.

For example:

 @override
  Widget build(BuildContext context) {
    // ...
    final controller = MoneyMaskedTextController(initialValue: someValue);
    // ...
   return Scaffold(
     // ...
     child: AutoSizeTextField(
        onChanged: (_) => _handleChange(controller.numberValue),
        autofocus: true,
        style: const TextStyle(fontSize: 48, color: Colors.white),
        textAlign: TextAlign.center,
        controller: controller,
        keyboardType: TextInputType.number,
        decoration: const InputDecoration.collapsed(hintText: '0.0'),
     ),
     // ...
   );

  _handleChange(controller) {
    setState(() { // this rebuild will make the autosize to stop working ....})
  }
neiljaywarner commented 1 year ago

@burekas7 can this be closed?