From 7b3f743c3c06bec24aad07e553c42cfc6326f282 Mon Sep 17 00:00:00 2001 From: Tomasz Gucio <72562119+tgucio@users.noreply.github.com> Date: Wed, 24 Apr 2024 00:30:06 +0200 Subject: [PATCH] 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. --- packages/flutter/lib/src/rendering/editable.dart | 14 +++----------- packages/flutter/lib/src/rendering/paragraph.dart | 8 +------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart index ba386545a6..e03b1d9995 100644 --- a/packages/flutter/lib/src/rendering/editable.dart +++ b/packages/flutter/lib/src/rendering/editable.dart @@ -2312,18 +2312,10 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, ..layout(minWidth: minWidth, maxWidth: maxWidth); positionInlineChildren(_textPainter.inlinePlaceholderBoxes!); _computeCaretPrototype(); - // We grab _textPainter.size here because assigning to `size` on the next - // line will trigger us to validate our intrinsic sizes, which will change - // _textPainter's layout because the intrinsic size calculations are - // destructive, which would mean we would get different results if we later - // used properties on _textPainter in this method. - // Other _textPainter state like didExceedMaxLines will also be affected, - // though we currently don't use those here. - // See also RenderParagraph which has a similar issue. - final Size textPainterSize = _textPainter.size; + final double width = forceLine ? constraints.maxWidth - : constraints.constrainWidth(_textPainter.size.width + _caretMargin); + : constraints.constrainWidth(_textPainter.width + _caretMargin); assert(maxLines != 1 || _textPainter.maxLines == 1); final double preferredHeight = switch (maxLines) { null => math.max(_textPainter.height, preferredLineHeight * (minLines ?? 0)), @@ -2336,7 +2328,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, }; size = Size(width, constraints.constrainHeight(preferredHeight)); - final Size contentSize = Size(textPainterSize.width + _caretMargin, textPainterSize.height); + final Size contentSize = Size(_textPainter.width + _caretMargin, _textPainter.height); final BoxConstraints painterConstraints = BoxConstraints.tight(contentSize); diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index 5f2b62895a..13f3338bb8 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -809,16 +809,10 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin