Skip to content

Commit 7b3f743

Browse files
authored
Remove unneeded local variables and comments in Editable and RenderParagraph (#146843)
This PR removes unnecessary local variables and related comments in `Editable` and `RenderParagraph` as both now use another `TextPainter` instance for intrinsics cache. Test-exempt: minor refactor and comments.
1 parent 9ebf80a commit 7b3f743

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

packages/flutter/lib/src/rendering/editable.dart

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,18 +2312,10 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
23122312
..layout(minWidth: minWidth, maxWidth: maxWidth);
23132313
positionInlineChildren(_textPainter.inlinePlaceholderBoxes!);
23142314
_computeCaretPrototype();
2315-
// We grab _textPainter.size here because assigning to `size` on the next
2316-
// line will trigger us to validate our intrinsic sizes, which will change
2317-
// _textPainter's layout because the intrinsic size calculations are
2318-
// destructive, which would mean we would get different results if we later
2319-
// used properties on _textPainter in this method.
2320-
// Other _textPainter state like didExceedMaxLines will also be affected,
2321-
// though we currently don't use those here.
2322-
// See also RenderParagraph which has a similar issue.
2323-
final Size textPainterSize = _textPainter.size;
2315+
23242316
final double width = forceLine
23252317
? constraints.maxWidth
2326-
: constraints.constrainWidth(_textPainter.size.width + _caretMargin);
2318+
: constraints.constrainWidth(_textPainter.width + _caretMargin);
23272319
assert(maxLines != 1 || _textPainter.maxLines == 1);
23282320
final double preferredHeight = switch (maxLines) {
23292321
null => math.max(_textPainter.height, preferredLineHeight * (minLines ?? 0)),
@@ -2336,7 +2328,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
23362328
};
23372329

23382330
size = Size(width, constraints.constrainHeight(preferredHeight));
2339-
final Size contentSize = Size(textPainterSize.width + _caretMargin, textPainterSize.height);
2331+
final Size contentSize = Size(_textPainter.width + _caretMargin, _textPainter.height);
23402332

23412333
final BoxConstraints painterConstraints = BoxConstraints.tight(contentSize);
23422334

packages/flutter/lib/src/rendering/paragraph.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -809,16 +809,10 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
809809
_layoutTextWithConstraints(constraints);
810810
positionInlineChildren(_textPainter.inlinePlaceholderBoxes!);
811811

812-
// We grab _textPainter.size and _textPainter.didExceedMaxLines here because
813-
// assigning to `size` will trigger us to validate our intrinsic sizes,
814-
// which will change _textPainter's layout because the intrinsic size
815-
// calculations are destructive. Other _textPainter state will also be
816-
// affected. See also RenderEditable which has a similar issue.
817812
final Size textSize = _textPainter.size;
818-
final bool textDidExceedMaxLines = _textPainter.didExceedMaxLines;
819813
size = constraints.constrain(textSize);
820814

821-
final bool didOverflowHeight = size.height < textSize.height || textDidExceedMaxLines;
815+
final bool didOverflowHeight = size.height < textSize.height || _textPainter.didExceedMaxLines;
822816
final bool didOverflowWidth = size.width < textSize.width;
823817
// TODO(abarth): We're only measuring the sizes of the line boxes here. If
824818
// the glyphs draw outside the line boxes, we might think that there isn't

0 commit comments

Comments
 (0)