Skip to content

Add hyphenCharacter to TextPainter, RenderParagraph, RichText and Text - #196152

Open
dbebawy wants to merge 1 commit into
flutter:masterfrom
dbebawy:hyphen-character-framework-189617
Open

dbebawy wants to merge 1 commit into
flutter:masterfrom
dbebawy:hyphen-character-framework-189617

Conversation

@dbebawy

@dbebawy dbebawy commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Adds hyphenCharacter to TextStyle.getParagraphStyle, TextPainter, RenderParagraph, RichText and Text, so apps can choose the string drawn at the end of a line that breaks at a soft hyphen (U+00AD). It passes through the same way as hyphens and ends up in ParagraphStyle.hyphenCharacter from #195345. If it is null, "-" is drawn as before. The empty string draws nothing, and the line still breaks there.

The new getParagraphStyle parameter breaks classes that override it, so I think this needs a breaking change page. The only override I found in this repo is a test one, updated here in theme_test.dart. The page is in flutter/website#14048, and I am happy to change the shape of this if there is a better way to do it.

Fixes #189617.

Pre-launch Checklist

Passes the string drawn at a soft hyphen line break through
TextStyle.getParagraphStyle to dart:ui's ParagraphStyle.hyphenCharacter,
the same way as hyphens.

Part of flutter#189617
@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels Nov 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for a custom hyphenCharacter across Flutter's text rendering stack, including TextPainter, TextStyle, RenderParagraph, RichText, and Text widgets, allowing developers to customize the character displayed at soft hyphen line breaks. The review feedback points out that the _TextStyleProxy.getParagraphStyle method in tests was updated to accept the new hyphenCharacter parameter but fails to forward it to its delegate, which should be resolved to ensure correct proxy behavior.

int? maxLines,
ui.TextHeightBehavior? textHeightBehavior,
Hyphens? hyphens,
String? hyphenCharacter,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The _TextStyleProxy.getParagraphStyle method signature was updated to include hyphenCharacter, but the method body does not forward this parameter to the delegate. To maintain correct proxy behavior, pass hyphenCharacter: hyphenCharacter to the delegate's getParagraphStyle call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I don't think there's anything to forward here, since this proxy's getParagraphStyle just throws UnimplementedError and doesn't call a delegate. It only needed the new parameter so the override still compiles.

@dkwingsmt dkwingsmt added team-text-input Owned by Text Input team and removed p: material_ui material_ui package in flutter/packages labels Nov 10, 2026
@dbebawy

dbebawy commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

@gaaclarke would you mind taking a look at this when you have a chance? It's the framework half of #195345, which you reviewed, and it needs the CICD label to run the full tests. Thanks!

@gaaclarke gaaclarke added team-framework Owned by Framework team team-text-input Owned by Text Input team and removed team-text-input Owned by Text Input team team-framework Owned by Framework team labels Nov 11, 2026
@gaaclarke

Copy link
Copy Markdown
Member

@gaaclarke would you mind taking a look at this when you have a chance? It's the framework half of #195345, which you reviewed, and it needs the CICD label to run the full tests. Thanks!

This is outside my jurisdiction =)

@dbebawy

dbebawy commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @gaaclarke, sorry about that!

@Renzo-Olivares would you mind taking a look when you have a chance, or pointing me to the right reviewer? It needs the CICD label to run the full tests. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. team-text-input Owned by Text Input team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support customizing the soft-hyphen character/string

3 participants