Skip to content

Conversation

@shindonghwi
Copy link
Contributor

@shindonghwi shindonghwi commented Dec 15, 2025

Problem

When you change textAlign on a RenderParagraph, the parent widget doesn't know the layout changed.

Example: If you use LayoutBuilder to position elements based on text alignment, changing from TextAlign.left to TextAlign.right won't trigger a rebuild - even though the text moved.

Cause

The textAlign setter was calling markNeedsPaint() (just repaint) instead of markNeedsLayout() (recalculate layout).

Fix

One line change: markNeedsPaint()markNeedsLayout()

This matches how other setters like textDirection and softWrap already work.

Fixes

#140756

Pre-launch Checklist

The textAlign setter was only calling markNeedsPaint(), which meant
that parent widgets using LayoutBuilder would not be notified when
text alignment changed. This fix changes it to call markNeedsLayout()
instead, consistent with other setters like textDirection and softWrap
that affect layout.

Fixes flutter#140756
@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Dec 15, 2025
Copy link
Contributor

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

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 correctly changes the textAlign setter in RenderParagraph to call markNeedsLayout() instead of markNeedsPaint(). This change ensures that modifying the text alignment properly invalidates the layout, which is consistent with other layout-related properties in the class. The test for this behavior has also been updated to reflect the fix, now correctly asserting that debugNeedsLayout is true after the property change and using pumpFrame() to process the layout.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍 . This makes sense to me but maybe @LongCatIsLooong can double check me here. I guess changing textAlign (or textDirection) would never change the height or width of the RenderParagraph, only the position of the text. In @shindonghwi's use case of positioning something on top of the text, that still matters for their layout. So should we consider stuff like this to require relayout then or should we expect the user to do something else if they're positioning based on the text location?

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

After reading the issue (#140756) I'm not convinced we want to do this. @LongCatIsLooong do you still have any plans to provide a way to be notified of text layout changes?

@LongCatIsLooong
Copy link
Contributor

LongCatIsLooong commented Dec 31, 2025

When you change textAlign on a RenderParagraph, the parent widget doesn't know the layout changed.

The framework does not guarantee that a RenderObject will be notified when a descendant changes layout in general. It is indeed a problem that there's no good solution for monitoring the text layout changes of a RenderParagraph or RenderEditable, but I don't think relying on markNeedsLayout or using a LayoutBuilder is the best solution.

@justinmc
Copy link
Contributor

@shindonghwi Thanks for trying out a solution here, but it looks like we're going to need a more complete solution to solve this. We can continue discussion on the issue (#140756) and hopefully come up with a way to be notified of text layout changes.

@justinmc justinmc closed this Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants