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.03k stars 235 forks source link

Single character not resizing #92

Open DaemonInc opened 3 years ago

DaemonInc commented 3 years ago

Steps to Reproduce Text is not resizing when it is only a single character.

Code sample

LayoutBuilder(
  builder: (context, constraints) {
    return Container(
      padding: EdgeInsets.symmetric(
        vertical: 0.05 * constraints.biggest.height,
        horizontal: 0.08 * constraints.biggest.width,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Expanded(
            child: Container(
              color: Colors.blue,
              child: Align(
                alignment: Alignment.center,
                child: AutoSizeText(
                  "W",
                  style: Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 30.0.sp, fontWeight: FontWeight.normal),
                  textAlign: TextAlign.center,
                  minFontSize: 1,
                  maxLines: 1,
                  wrapWords: false,
                  softWrap: false,
                ),
              ),
            ),
          ),
          Container(
            color: Colors.red,
            alignment: Alignment.bottomRight,
            height: constraints.biggest.height * 0.35,
            child: AutoSizeText(
              "10",
              textAlign: TextAlign.end,
              minFontSize: 3.0.sp,
              style: theme.textTheme.bodyText2.copyWith(fontSize: 30.0.sp, fontWeight: FontWeight.normal),
              wrapWords: false,
              softWrap: false,
              overflow: false,
            ),
          ),
        ],
      ),
    );
  },
)

Screenshots image

image

Version

kidylee commented 1 year ago

Same issue here, the issue is because textPainter.didExceedMaxLines always return true for single character.