auto_size_text icon indicating copy to clipboard operation
auto_size_text copied to clipboard

AutoSizeGroup doesn't work on web/Android

Open MarcVanDaele90 opened this issue 3 years ago • 3 comments

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 image Screenshot_20221026-164845_Chrome

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

MarcVanDaele90 avatar Oct 26 '22 15:10 MarcVanDaele90

This is apparently triggered by https://github.com/flutter/flutter/issues/65940

MarcVanDaele90 avatar Oct 27 '22 07:10 MarcVanDaele90

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)

MarcVanDaele90 avatar Oct 27 '22 07:10 MarcVanDaele90

It seems flutter/engine#34085 PR did fix the issue it is available in Flutter 3.7.0 stable release.

maRci002 avatar Jan 26 '23 15:01 maRci002