Flutter TextField - how to shrink the font if the text entered overflows

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Flutter TextField - how to shrink the font if the text entered overflows



I have a TextField (not a Text) widget that must remain on one line. I want to reduce it's font size if the text entered is too large for the TextField box, ie shrink it if it overflows. How can I do this?



I have written some code like this in a stateful component


if (textLength < 32) {
newAutoTextVM.fontSize = 35.0;
} else if (textLength < 42) {
newAutoTextVM.fontSize = 25.0;



In the view


fontSize: 25.0,



but it isn't very intelligent, it doesn't cope with resizing, also, because the font size isn't monospaced (courier etc), different characters take up different amounts of space.




1 Answer
1



I have searched through the docs and found a couple of solutions that could come at your help:



Depending on the rest of your code one of these solutions could be better, try tweaking around.

Hope it helps.





thank you but TextField doesn't have those properties (these all apply to Text)
– orangesherbert
5 mins ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Better method to check all objects' parameters with a single call