Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
burekas7 opened this issue Sep 3, 2022 · 2 comments
Open

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

burekas7 opened this issue Sep 3, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@burekas7
Copy link

burekas7 commented Sep 3, 2022

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

  • Flutter version: 3.0.0.
  • auto_size_text version: 3.0.0
@burekas7 burekas7 added the bug Something isn't working label Sep 3, 2022
@gentunian
Copy link

gentunian commented May 29, 2023

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
Copy link

@burekas7 can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants