Unverified Commit 4bae7715 authored by MH Johnson's avatar MH Johnson Committed by GitHub

[Line Heights] Add textHeightBehavior to SelectableText. (#58530)

parent 79e24094
...@@ -221,6 +221,7 @@ class SelectableText extends StatefulWidget { ...@@ -221,6 +221,7 @@ class SelectableText extends StatefulWidget {
this.enableInteractiveSelection = true, this.enableInteractiveSelection = true,
this.onTap, this.onTap,
this.scrollPhysics, this.scrollPhysics,
this.textHeightBehavior,
this.textWidthBasis, this.textWidthBasis,
}) : assert(showCursor != null), }) : assert(showCursor != null),
assert(autofocus != null), assert(autofocus != null),
...@@ -270,6 +271,7 @@ class SelectableText extends StatefulWidget { ...@@ -270,6 +271,7 @@ class SelectableText extends StatefulWidget {
this.enableInteractiveSelection = true, this.enableInteractiveSelection = true,
this.onTap, this.onTap,
this.scrollPhysics, this.scrollPhysics,
this.textHeightBehavior,
this.textWidthBasis, this.textWidthBasis,
}) : assert(showCursor != null), }) : assert(showCursor != null),
assert(autofocus != null), assert(autofocus != null),
...@@ -406,6 +408,9 @@ class SelectableText extends StatefulWidget { ...@@ -406,6 +408,9 @@ class SelectableText extends StatefulWidget {
/// {@macro flutter.widgets.editableText.scrollPhysics} /// {@macro flutter.widgets.editableText.scrollPhysics}
final ScrollPhysics scrollPhysics; final ScrollPhysics scrollPhysics;
/// {@macro flutter.dart:ui.textHeightBehavior}
final TextHeightBehavior textHeightBehavior;
/// {@macro flutter.painting.textPainter.textWidthBasis} /// {@macro flutter.painting.textPainter.textWidthBasis}
final TextWidthBasis textWidthBasis; final TextWidthBasis textWidthBasis;
...@@ -430,6 +435,7 @@ class SelectableText extends StatefulWidget { ...@@ -430,6 +435,7 @@ class SelectableText extends StatefulWidget {
properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor, defaultValue: null)); properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor, defaultValue: null));
properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled'));
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
properties.add(DiagnosticsProperty<TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null));
} }
} }
...@@ -598,6 +604,7 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive ...@@ -598,6 +604,7 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
style: effectiveTextStyle, style: effectiveTextStyle,
readOnly: true, readOnly: true,
textWidthBasis: widget.textWidthBasis ?? defaultTextStyle.textWidthBasis, textWidthBasis: widget.textWidthBasis ?? defaultTextStyle.textWidthBasis,
textHeightBehavior: widget.textHeightBehavior ?? defaultTextStyle.textHeightBehavior,
showSelectionHandles: _showSelectionHandles, showSelectionHandles: _showSelectionHandles,
showCursor: widget.showCursor, showCursor: widget.showCursor,
controller: _controller, controller: _controller,
......
...@@ -212,6 +212,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -212,6 +212,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
this.ignorePointer = false, this.ignorePointer = false,
bool readOnly = false, bool readOnly = false,
bool forceLine = true, bool forceLine = true,
TextHeightBehavior textHeightBehavior,
TextWidthBasis textWidthBasis = TextWidthBasis.parent, TextWidthBasis textWidthBasis = TextWidthBasis.parent,
String obscuringCharacter = '•', String obscuringCharacter = '•',
bool obscureText = false, bool obscureText = false,
...@@ -264,6 +265,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -264,6 +265,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
locale: locale, locale: locale,
strutStyle: strutStyle, strutStyle: strutStyle,
textHeightBehavior: textHeightBehavior,
textWidthBasis: textWidthBasis, textWidthBasis: textWidthBasis,
), ),
_cursorColor = cursorColor, _cursorColor = cursorColor,
...@@ -322,6 +324,15 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -322,6 +324,15 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
/// The default value of this property is false. /// The default value of this property is false.
bool ignorePointer; bool ignorePointer;
/// {@macro flutter.dart:ui.textHeightBehavior}
TextHeightBehavior get textHeightBehavior => _textPainter.textHeightBehavior;
set textHeightBehavior(TextHeightBehavior value) {
if (_textPainter.textHeightBehavior == value)
return;
_textPainter.textHeightBehavior = value;
markNeedsTextLayout();
}
/// {@macro flutter.widgets.text.DefaultTextStyle.textWidthBasis} /// {@macro flutter.widgets.text.DefaultTextStyle.textWidthBasis}
TextWidthBasis get textWidthBasis => _textPainter.textWidthBasis; TextWidthBasis get textWidthBasis => _textPainter.textWidthBasis;
set textWidthBasis(TextWidthBasis value) { set textWidthBasis(TextWidthBasis value) {
......
...@@ -375,6 +375,7 @@ class EditableText extends StatefulWidget { ...@@ -375,6 +375,7 @@ class EditableText extends StatefulWidget {
this.minLines, this.minLines,
this.expands = false, this.expands = false,
this.forceLine = true, this.forceLine = true,
this.textHeightBehavior,
this.textWidthBasis = TextWidthBasis.parent, this.textWidthBasis = TextWidthBasis.parent,
this.autofocus = false, this.autofocus = false,
bool showCursor, bool showCursor,
...@@ -486,6 +487,9 @@ class EditableText extends StatefulWidget { ...@@ -486,6 +487,9 @@ class EditableText extends StatefulWidget {
/// {@endtemplate} /// {@endtemplate}
final bool obscureText; final bool obscureText;
/// {@macro flutter.dart:ui.textHeightBehavior},
final TextHeightBehavior textHeightBehavior;
/// {@macro flutter.widgets.text.DefaultTextStyle.textWidthBasis} /// {@macro flutter.widgets.text.DefaultTextStyle.textWidthBasis}
final TextWidthBasis textWidthBasis; final TextWidthBasis textWidthBasis;
...@@ -1146,6 +1150,7 @@ class EditableText extends StatefulWidget { ...@@ -1146,6 +1150,7 @@ class EditableText extends StatefulWidget {
properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null)); properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null));
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
properties.add(DiagnosticsProperty<Iterable<String>>('autofillHints', autofillHints, defaultValue: null)); properties.add(DiagnosticsProperty<Iterable<String>>('autofillHints', autofillHints, defaultValue: null));
properties.add(DiagnosticsProperty<TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null));
} }
} }
...@@ -2085,6 +2090,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -2085,6 +2090,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
textAlign: widget.textAlign, textAlign: widget.textAlign,
textDirection: _textDirection, textDirection: _textDirection,
locale: widget.locale, locale: widget.locale,
textHeightBehavior: widget.textHeightBehavior,
textWidthBasis: widget.textWidthBasis, textWidthBasis: widget.textWidthBasis,
obscuringCharacter: widget.obscuringCharacter, obscuringCharacter: widget.obscuringCharacter,
obscureText: widget.obscureText, obscureText: widget.obscureText,
...@@ -2149,6 +2155,7 @@ class _Editable extends LeafRenderObjectWidget { ...@@ -2149,6 +2155,7 @@ class _Editable extends LeafRenderObjectWidget {
this.showCursor, this.showCursor,
this.forceLine, this.forceLine,
this.readOnly, this.readOnly,
this.textHeightBehavior,
this.textWidthBasis, this.textWidthBasis,
this.hasFocus, this.hasFocus,
this.maxLines, this.maxLines,
...@@ -2206,6 +2213,7 @@ class _Editable extends LeafRenderObjectWidget { ...@@ -2206,6 +2213,7 @@ class _Editable extends LeafRenderObjectWidget {
final Locale locale; final Locale locale;
final String obscuringCharacter; final String obscuringCharacter;
final bool obscureText; final bool obscureText;
final TextHeightBehavior textHeightBehavior;
final TextWidthBasis textWidthBasis; final TextWidthBasis textWidthBasis;
final bool autocorrect; final bool autocorrect;
final SmartDashesType smartDashesType; final SmartDashesType smartDashesType;
...@@ -2255,6 +2263,7 @@ class _Editable extends LeafRenderObjectWidget { ...@@ -2255,6 +2263,7 @@ class _Editable extends LeafRenderObjectWidget {
ignorePointer: rendererIgnoresPointer, ignorePointer: rendererIgnoresPointer,
obscuringCharacter: obscuringCharacter, obscuringCharacter: obscuringCharacter,
obscureText: obscureText, obscureText: obscureText,
textHeightBehavior: textHeightBehavior,
textWidthBasis: textWidthBasis, textWidthBasis: textWidthBasis,
cursorWidth: cursorWidth, cursorWidth: cursorWidth,
cursorRadius: cursorRadius, cursorRadius: cursorRadius,
...@@ -2295,6 +2304,7 @@ class _Editable extends LeafRenderObjectWidget { ...@@ -2295,6 +2304,7 @@ class _Editable extends LeafRenderObjectWidget {
..onSelectionChanged = onSelectionChanged ..onSelectionChanged = onSelectionChanged
..onCaretChanged = onCaretChanged ..onCaretChanged = onCaretChanged
..ignorePointer = rendererIgnoresPointer ..ignorePointer = rendererIgnoresPointer
..textHeightBehavior = textHeightBehavior
..textWidthBasis = textWidthBasis ..textWidthBasis = textWidthBasis
..obscuringCharacter = obscuringCharacter ..obscuringCharacter = obscuringCharacter
..obscureText = obscureText ..obscureText = obscureText
......
...@@ -374,6 +374,30 @@ void main() { ...@@ -374,6 +374,30 @@ void main() {
expect(textBox.size, const Size(633.0, 28.0)); expect(textBox.size, const Size(633.0, 28.0));
}); });
testWidgets('can switch between textHeightBehavior', (WidgetTester tester) async {
const String text = 'selectable text';
const TextHeightBehavior textHeightBehavior = TextHeightBehavior(
applyHeightToFirstAscent: false,
applyHeightToLastDescent: false,
);
await tester.pumpWidget(
boilerplate(
child: const SelectableText(text),
),
);
expect(findRenderEditable(tester).textHeightBehavior, isNull);
await tester.pumpWidget(
boilerplate(
child: const SelectableText(
text,
textHeightBehavior: textHeightBehavior,
),
),
);
expect(findRenderEditable(tester).textHeightBehavior, textHeightBehavior);
});
testWidgets('Cursor blinks when showCursor is true', (WidgetTester tester) async { testWidgets('Cursor blinks when showCursor is true', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
overlay( overlay(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment