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

Not resizing small enough on Android Chrome on Web #130

Open
DannyJoinedApps opened this issue Jan 24, 2023 · 2 comments
Open

Not resizing small enough on Android Chrome on Web #130

DannyJoinedApps opened this issue Jan 24, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@DannyJoinedApps
Copy link

Steps to Reproduce
Run web app on desktop in any browser, fonts are resized just fine. Run it on chrome on android, and the test always shows with just a little bit missing, about 5-10% of the words. The font does get resized, just not quite enough to fit everything on. Note that it is not a restrictive lower bound on the font size as you can choose a longer string and your library will choose a smaller font within its range, just not quite small enough to actually fit in all the words. Note that it works very nicely on desktop browsers that I have tested so far.

Code sample

Container(
        width:w, height: h,
        child: AutoSizeText(
          questionText, style:questionTextStyle, minFontSize: 10, maxFontSize: 80, maxLines: 3,
          textAlign: TextAlign.center,))

Version

  • Flutter version: 3.3.10
  • auto_size_text version: 3.0.0
@DannyJoinedApps DannyJoinedApps added the bug Something isn't working label Jan 24, 2023
@DannyJoinedApps
Copy link
Author

Hi, sorry to update this with such a small update, but in case it helps anyone. This appears to be an issue on chrome on Android and on Safari on iOS (at least the emulator in xCode, I haven't got an iPhone.

I think I have narrowed it down to the _checkTextFits() function, incorrectly finding that text does fit at a font size (or rather scale) than it should. I have checked the values of everything (width of original container against the 'size' object passed into and through everything to get into that function, the scale calc makes sense, the fontSize and so on, all makes sense comparing mobile web, to PC web), then it gets through to flutter's TextPainter() class and it's layout() function. This function seems to being given very reasonable values (I've done a LOT of experimenting with a certain font and some text and container sizes, manually creating Text() widgets and so on, so I know what should fit in a certain container on one row) and that method is giving a 'didExceedMaxLines = false, when it really shouldn't. And its not close, its doing this at a font size more than 1.5 times that which will really fit in a container.

Having tracked it down to this I can now try things like changing final textPainter = TextPainter(.... textScaleFactor: scale * 1.5 ...) to experiment. I can also do the inverse and trick it by reducing the constraints.maxWidth in the .layout function. It seems the magic number for the particular iOS device (emulator) is about 1.63, That causes the while loop above to home in on a scale and hence a font size which just fits inside the container.

I'm still hopeful that there is something I'm doing wrong to cause this, but its a pretty simple implementation. I have tried getting the MaterialApp to reset the textScaleFactor in case its that. Its a shame as I was controlling my layout with containers all scaled perfectly and if I need to manually calculate some okay-ish font sizes for the various bits of text, I'll have to err on the side of caution and undersize all the text a bit, this library/plugin does a PERFECT job on PC browsers, app was looking really polished. Again, still hoping you can't replicate this and its something dumb I'm doing.

@DannyJoinedApps
Copy link
Author

Okay, sorry, this is very possibly the same issue as #86. At least the fix proposed there using the canvaskit, immediately solves the problem. Not sure what else that might do, but testing so far it seems to be fine.

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

1 participant