marcglasberg/assorted_layout_widgets

TextOneLine: Letterspacing rendered different

AFAS-HHO opened this issue · 3 comments

image

Code to reproduce (assuming usage of GoogleFonts package)

 final TextStyle style = GoogleFonts.inter(
      fontSize: 10,
      fontWeight: FontWeight.w500,
      letterSpacing: 1.1,
    );
    const String textValue =
        'Consectetur adipiscing elit. Et sept en andor cras massa mass';

    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          TextOneLine(
            textValue,
            style: style,
          ),
          const SizedBox(height: 4.0),
          Text(
            textValue,
            style: style,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
        ],
      ),
    );`

TextOneLine seems to render extra letter spacing, This is also the case with a default letter spacing, giving it a higher value seems to make the difference even greater.

After further looking into it it seems that that Zero-width space still applies letter spacing.

My suggestion is to apply on the textStyle with a letterSpacingFactor of 0.5

.apply(
    letterSpacingFactor: 0.5
);

I've never used letterSpacing, so I've never experienced this. Clearly, TextOneLine is incompatible with letterSpacing. I believe .apply(letterSpacingFactor: 0.5); should solve it, unless this introduces some other problem I can't see right now. I will apply this fix.

The TextOneLine widget was never supposed to exist for that long, it was just a temporary fix for the wrapping problem. Hope they fix that one day so that I can deprecate this widget.

Just published versions 7.0.1 and 8.0.0 with the fix. Thank you for proposing the fix!

Known issue: The letter-spacing will work fine when the style is defined inline, but it may not work fine when the style is inherited.