flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.02k stars 27.19k forks source link

[Text] Line decorations are not drawing with end spaces #107725

Open AlexV525 opened 2 years ago

AlexV525 commented 2 years ago

Steps to Reproduce

  1. Use the counter snippets.
  2. Change the counter text to the below code.
  3. The underline is not drawn with spaces.
Text(
  '$_counter       ',
  style: Theme.of(context).textTheme.headline4?.copyWith(
    decoration: TextDecoration.underline,
  ),
)

Expected results:

image

Actual results:

image

Additional context

The workaround for this single issue is pretty straightforward. Adding a zero-width character \u{200b} at the end will make the decoration work again.

Text(
  '$_counter      \u{200b} ',
  style: Theme.of(context).textTheme.headline4?.copyWith(
    decoration: TextDecoration.underline,
  ),
)
AlexV525 commented 2 years ago

So IMO the decoration paint is losing track when spaces are added at the end, which makes the area transparent, then the paint might be decided not to draw on it.

chinmaygarde commented 2 years ago

This is working as intended and matches behavior in the browsers as well.

shirne commented 2 years ago

code https://github.com/shirne/tester/blob/master/lib/text_page.dart flutter run -d chrome flutter run -d chrome flutter run -d chrome --web-renderer=html flutter run -d chrome --web-renderer=html

AlexV525 commented 2 years ago

This is working as intended and matches behavior in the browsers as well.

It matches the default behavior in the browser, but after you tweak the element's style, the underline can be extended to the whole text.

image

Reopening since it's likely to have an opt-in implementation here.

danagbemava-nc commented 1 year ago

This also happens with the other line decorations (lineThrough & overline). See https://github.com/flutter/flutter/issues/132816 which uses a font that draws all three lines at the same time.