lzhuor / auto_size_text_field

Flutter TextField widget that automatically resizes text field to fit perfectly within its bounds.
https://pub.dev/packages/auto_size_text_field
MIT License
51 stars 34 forks source link

Widget not configured properly. Text does not resize #21

Closed LEMUSADR000 closed 1 year ago

LEMUSADR000 commented 3 years ago

I have the widget code as such:

return Row(
   children: <Widget>[
     Expanded(
       child: AutoSizeTextField(
         controller: TextEditingController(text: name),
         decoration: InputDecoration(
           hintText: "Name",
         ),
       ),
     ),
   ],
 );

When I enter input it scrolls to the right but does not limit the size of the input in any way. Why is this?

I've also tried

SizedBox(
  child: AutoSizeTextField(
    controller: TextEditingController(text: name),
    decoration: InputDecoration(
      hintText: "Name",
    ),
  ),
  width: 200,
);

And get the same results but in a smaller box. Are there some theme data that I need to provide? What is going on. Currently this works 0% of the time.

manylittlestorms commented 2 years ago

Same issue...

DowsingUK commented 2 years ago

Same here...

manylittlestorms commented 2 years ago

@lzhuor Any chance you could look into this? I have a Row --> Expanded --> AutoSizeTextField like OP, but it doesn't resize.

lzhuor commented 2 years ago

Hi @DowsingUK, please bear in mind that the parent has to be a constrained Box element in Flutter otherwise this widget does not work.

Hi @manylittlestorms, Row -> Expanded -> AutoSizeTextField should work. Did you try to inspect the element and see if size constraints are in the properties of the Widget element?

Further more: Could you please try the following?

DowsingUK commented 2 years ago

Good day, it's working very well in other devices, lately I tried with an AndroidTV in a huge screen and it worked like a charm, but in some tablets and some iPhones Plus it is not working at all I even have tried compiling project's example as it is and no one single font got resized on those devices

lzhuor commented 2 years ago

Hi @DowsingUK I might roughly find the root cause. Will share more details later. Thanks to my teammate!

DowsingUK commented 2 years ago

Great we all be waiting, thank you so much!

manylittlestorms commented 2 years ago

Hi @DowsingUK I might roughly find the root cause. Will share more details later. Thanks to my teammate!

Thank you. Waiting for a fix.

Raph22 commented 2 years ago

Hello, I m not sure it's related to that issue but for me the example (https://github.com/lzhuor/auto_size_text_field/blob/master/example/lib/main.dart) doesn't work except the last one, "multi line text with input padding". I don't need the multi lines usage in my case but for those who are interested I make it working with one line input by removing maxWidth: constraintWidth from tp.layout line 790. But it breaks the multi lines. Maybe I'll try to open a PR to solve that issue as well but I m new to Dart and Flutter and not a lot of free time to do. Also, about the first example given by the author of the issue, I notice that the controller shouldn't be initialize when passed to the constructor AutoSizeTextField but be declared before in a variable and pass it to the constructor. I m using a Galaxy S10 with Android 11. Otherwise thanks for that package 😄

lzhuor commented 2 years ago

Hi @Raph22 Thank you very much for the explanation. I am sorry that my day job has been making me occupied due to year-end stuff. Looking forward to your PR and thank you for the kind words!

lzhuor commented 2 years ago

Hi @DowsingUK @manylittlestorms @Raph22 @LEMUSADR000 , I found that for some Android 11 and above devices, we have to explicitly set the constraints to get it to work. The temporary workaround is:

Container(
    constraints: BoxConstraints(maxWidth: 280),
    child: AutoSizeTextField()
)
lzhuor commented 2 years ago

Closed as no more follow-ups with the provided solution.

pomarec commented 1 year ago

Where does the value 280 comes from ? You have to know the value of the width beforhand ? It is the anti-usage of Expanded in a Row in my understanding.

manylittlestorms commented 1 year ago

Hi @DowsingUK @manylittlestorms @Raph22 @LEMUSADR000 , I found that for some Android 11 and above devices, we have to explicitly set the constraints to get it to work. The temporary workaround is:


Container(

    constraints: BoxConstraints(maxWidth: 280),

    child: AutoSizeTextField()

)

Having to set a constraint is a problem, since we wanted to use Expanded because we don't know how much width it will get...

pomarec commented 1 year ago

@lzhuor Do you think this issue should be re-opened ? The provided solution is actually not a solution but a fake workaround as explained by @manylittlestorms

manylittlestorms commented 1 year ago

@lzhuor Do you think this issue should be re-opened ? The provided solution is actually not a solution but a fake workaround as explained by @manylittlestorms

It should be re-opened in my opinion. @lzhuor

JohnnyRainbow81 commented 1 year ago

Same issue here.

lzhuor commented 1 year ago

Hi buddies, how this widget works is that it detects the box constraints to compute the optimal textual size.

It's impossible to know the optimal textual size without box constraints. As you mentioned, with <Expanded /> this widget expects to know the boundary constraint but does not.

This is likely a separate issue in Flutter instead of this library. Would love to discuss this with you.

If you can create an example app with this issue, we might be able to help.,