@@ -687,7 +687,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
687
687
final TextRange line = _textPainter.getLineBoundary (position);
688
688
// If text is obscured, the entire string should be treated as one line.
689
689
if (obscureText) {
690
- return TextSelection (baseOffset: 0 , extentOffset: _plainText .length);
690
+ return TextSelection (baseOffset: 0 , extentOffset: plainText .length);
691
691
}
692
692
return TextSelection (baseOffset: line.start, extentOffset: line.end);
693
693
}
@@ -756,12 +756,12 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
756
756
757
757
void _setSelection (TextSelection nextSelection, SelectionChangedCause cause) {
758
758
if (nextSelection.isValid) {
759
- // The nextSelection is calculated based on _plainText , which can be out
759
+ // The nextSelection is calculated based on plainText , which can be out
760
760
// of sync with the textSelectionDelegate.textEditingValue by one frame.
761
761
// This is due to the render editable and editable text handle pointer
762
762
// event separately. If the editable text changes the text during the
763
763
// event handler, the render editable will use the outdated text stored in
764
- // the _plainText when handling the pointer event.
764
+ // the plainText when handling the pointer event.
765
765
//
766
766
// If this happens, we need to make sure the new selection is still valid.
767
767
final int textLength = textSelectionDelegate.textEditingValue.text.length;
@@ -803,16 +803,16 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
803
803
_textLayoutLastMinWidth = null ;
804
804
}
805
805
806
- String ? _cachedPlainText;
807
- // Returns a plain text version of the text in the painter.
808
- //
809
- // Returns the obscured text when [obscureText] is true. See
810
- // [obscureText] and [obscuringCharacter].
811
- String get _plainText {
812
- return _cachedPlainText ?? = _textPainter.text! .toPlainText (includeSemanticsLabels: false );
813
- }
806
+ /// Returns a plain text version of the text in [TextPainter] .
807
+ ///
808
+ /// If [obscureText] is true, returns the obscured text. See
809
+ /// [obscureText] and [obscuringCharacter] .
810
+ /// In order to get the styled text as an [InlineSpan] tree, use [text] .
811
+ String get plainText => _textPainter.plainText;
814
812
815
- /// The text to display.
813
+ /// The text to paint in the form of a tree of [InlineSpan] s.
814
+ ///
815
+ /// In order to get the plain text representation, use [plainText] .
816
816
InlineSpan ? get text => _textPainter.text;
817
817
final TextPainter _textPainter;
818
818
AttributedString ? _cachedAttributedValue;
@@ -821,9 +821,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
821
821
if (_textPainter.text == value) {
822
822
return ;
823
823
}
824
- _cachedPlainText = null ;
825
824
_cachedLineBreakCount = null ;
826
-
827
825
_textPainter.text = value;
828
826
_cachedAttributedValue = null ;
829
827
_cachedCombinedSemanticsInfos = null ;
@@ -1328,7 +1326,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
1328
1326
}
1329
1327
if (_cachedAttributedValue == null ) {
1330
1328
if (obscureText) {
1331
- _cachedAttributedValue = AttributedString (obscuringCharacter * _plainText .length);
1329
+ _cachedAttributedValue = AttributedString (obscuringCharacter * plainText .length);
1332
1330
} else {
1333
1331
final StringBuffer buffer = StringBuffer ();
1334
1332
int offset = 0 ;
@@ -1855,23 +1853,24 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
1855
1853
if (maxLines == null ) {
1856
1854
final double estimatedHeight;
1857
1855
if (width == double .infinity) {
1858
- estimatedHeight = preferredLineHeight * (_countHardLineBreaks (_plainText ) + 1 );
1856
+ estimatedHeight = preferredLineHeight * (_countHardLineBreaks (plainText ) + 1 );
1859
1857
} else {
1860
1858
_layoutText (maxWidth: width);
1861
1859
estimatedHeight = _textPainter.height;
1862
1860
}
1863
1861
return math.max (estimatedHeight, minHeight);
1864
1862
}
1863
+
1865
1864
// TODO(LongCatIsLooong): this is a workaround for
1866
- // https://github.com/flutter/flutter/issues/112123 .
1865
+ // https://github.com/flutter/flutter/issues/112123.
1867
1866
// Use preferredLineHeight since SkParagraph currently returns an incorrect
1868
1867
// height.
1869
1868
final TextHeightBehavior ? textHeightBehavior = this .textHeightBehavior;
1870
1869
final bool usePreferredLineHeightHack = maxLines == 1
1871
- && text? .codeUnitAt (0 ) == null
1872
- && strutStyle != null && strutStyle != StrutStyle .disabled
1873
- && textHeightBehavior != null
1874
- && (! textHeightBehavior.applyHeightToFirstAscent || ! textHeightBehavior.applyHeightToLastDescent);
1870
+ && text? .codeUnitAt (0 ) == null
1871
+ && strutStyle != null && strutStyle != StrutStyle .disabled
1872
+ && textHeightBehavior != null
1873
+ && (! textHeightBehavior.applyHeightToFirstAscent || ! textHeightBehavior.applyHeightToLastDescent);
1875
1874
1876
1875
// Special case maxLines == 1 since it forces the scrollable direction
1877
1876
// to be horizontal. Report the real height to prevent the text from being
@@ -2142,14 +2141,14 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
2142
2141
TextSelection _getWordAtOffset (TextPosition position) {
2143
2142
debugAssertLayoutUpToDate ();
2144
2143
// When long-pressing past the end of the text, we want a collapsed cursor.
2145
- if (position.offset >= _plainText .length) {
2144
+ if (position.offset >= plainText .length) {
2146
2145
return TextSelection .fromPosition (
2147
- TextPosition (offset: _plainText .length, affinity: TextAffinity .upstream)
2146
+ TextPosition (offset: plainText .length, affinity: TextAffinity .upstream)
2148
2147
);
2149
2148
}
2150
2149
// If text is obscured, the entire sentence should be treated as one word.
2151
2150
if (obscureText) {
2152
- return TextSelection (baseOffset: 0 , extentOffset: _plainText .length);
2151
+ return TextSelection (baseOffset: 0 , extentOffset: plainText .length);
2153
2152
}
2154
2153
final TextRange word = _textPainter.getWordBoundary (position);
2155
2154
final int effectiveOffset;
@@ -2170,7 +2169,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
2170
2169
// If the platform is Android and the text is read only, try to select the
2171
2170
// previous word if there is one; otherwise, select the single whitespace at
2172
2171
// the position.
2173
- if (TextLayoutMetrics .isWhitespace (_plainText .codeUnitAt (effectiveOffset))
2172
+ if (TextLayoutMetrics .isWhitespace (plainText .codeUnitAt (effectiveOffset))
2174
2173
&& effectiveOffset > 0 ) {
2175
2174
assert (defaultTargetPlatform != null );
2176
2175
final TextRange ? previousWord = _getPreviousWord (word.start);
0 commit comments