simc / auto_size_text

Flutter widget that automatically resizes text to fit perfectly within its bounds.
https://pub.dev/packages/auto_size_text
MIT License
2.06k stars 240 forks source link

AutoSizeGroup doesn't work on web/Android #126

Open MarcVanDaele90 opened 2 years ago

MarcVanDaele90 commented 2 years ago

Steps to Reproduce

The code below runs fine

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

MarcVanDaele90 commented 2 years ago

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

MarcVanDaele90 commented 2 years ago

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)

maRci002 commented 1 year ago

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