auto_size_text
auto_size_text copied to clipboard
AutoSizeGroup doesn't work on web/Android
Steps to Reproduce
- create a project with the code below
- build it using
flutter build web - put the build/web directory on a webserver
- access this url from both chrome/Linux (works fine) and from chrome/Android (does not work)
The code below runs fine
- on web(chrome)/Linux
- on Android (as app)
- but NOT on web(chrome)/Android In the later case, the autosizing does not seem to work.
Code sample
body: Row(
children:[
Spacer(flex:3),
Expanded(child: Card(child: AutoSizeText("aaa", group: autoSizeGroup, maxLines:1, minFontSize: 6, style: textStyle))),
Expanded(child: Card(child: AutoSizeText("somewhat longer", group: autoSizeGroup, maxLines: 1, minFontSize: 6, style: textStyle))),
Spacer(flex:3)
]
),
Screenshots
If applicable, add screenshots to help explain your problem.
Screenshot added from linux chrome browser and Android chrome browser. Same problem is observed on iOS/Chrome+safari

Version
- auto_size_text version: 3.0.0
- Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.5, on Linux Mint 20.2 5.15.0-46-generic, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2022.1) [✓] VS Code (version 1.70.1) [✓] Connected device (2 available) [✓] HTTP Host Availability
This is apparently triggered by https://github.com/flutter/flutter/issues/65940
I have a temporary workaround (which is inefficient and probably incomplete but it might be helpful to others).
I replaced textpainter.didExceedMaxLines with
final textPainter2 = TextPainter(
text: text,
textAlign: widget.textAlign ?? TextAlign.left,
textDirection: widget.textDirection ?? TextDirection.ltr,
textScaleFactor: scale,
maxLines: maxLines==null?maxLines:maxLines+1,
locale: widget.locale,
strutStyle: widget.strutStyle,
);
textPainter2.layout(maxWidth: constraints.maxWidth);
bool didExceedMaxLines = textPainter2.height>textPainter.height;
This fixes the issue on my side (note that I didn't touch wordWrapTextPainter because I didn't need this right now)
It seems flutter/engine#34085 PR did fix the issue it is available in Flutter 3.7.0 stable release.