diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 3899b3d157..2089775d00 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -29,6 +29,7 @@ import 'media_query.dart'; import 'scroll_controller.dart'; import 'scroll_physics.dart'; import 'scrollable.dart'; +import 'text.dart'; import 'text_selection.dart'; import 'ticker_provider.dart'; @@ -2253,7 +2254,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien textAlign: widget.textAlign, textDirection: _textDirection, locale: widget.locale, - textHeightBehavior: widget.textHeightBehavior, + textHeightBehavior: widget.textHeightBehavior ?? DefaultTextHeightBehavior.of(context), textWidthBasis: widget.textWidthBasis, obscuringCharacter: widget.obscuringCharacter, obscureText: widget.obscureText, diff --git a/packages/flutter/lib/src/widgets/text.dart b/packages/flutter/lib/src/widgets/text.dart index aad1ced8c2..8f9b85d3b5 100644 --- a/packages/flutter/lib/src/widgets/text.dart +++ b/packages/flutter/lib/src/widgets/text.dart @@ -203,8 +203,8 @@ class DefaultTextStyle extends InheritedTheme { } } -/// The [TextHeightBehavior] that will apply to descendant [Text] widgets which -/// have not explicitly set [Text.textHeightBehavior]. +/// The [TextHeightBehavior] that will apply to descendant [Text] and [EditableText] +/// widgets which have not explicitly set [Text.textHeightBehavior]. /// /// If there is a [DefaultTextStyle] with a non-null [DefaultTextStyle.textHeightBehavior] /// below this widget, the [DefaultTextStyle.textHeightBehavior] will be used diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index dc2edf17b2..8ec6728ca2 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -129,6 +129,7 @@ void main() { expect(editableText.enableSuggestions, isTrue); expect(editableText.textAlign, TextAlign.start); expect(editableText.cursorWidth, 2.0); + expect(editableText.textHeightBehavior, isNull); }); testWidgets('text keyboard is requested when maxLines is default', (WidgetTester tester) async { @@ -5062,6 +5063,70 @@ void main() { )); expect(renderObject.clipBehavior, equals(Clip.antiAlias)); }); + + testWidgets('EditableText inherits DefaultTextHeightBehavior', (WidgetTester tester) async { + const TextHeightBehavior customTextHeightBehavior = TextHeightBehavior( + applyHeightToLastDescent: true, + applyHeightToFirstAscent: false, + ); + await tester.pumpWidget(MediaQuery( + data: const MediaQueryData(devicePixelRatio: 1.0), + child: Directionality( + textDirection: TextDirection.ltr, + child: FocusScope( + node: focusScopeNode, + autofocus: true, + child: DefaultTextHeightBehavior( + textHeightBehavior: customTextHeightBehavior, + child: EditableText( + backgroundCursorColor: Colors.grey, + controller: controller, + focusNode: focusNode, + style: textStyle, + cursorColor: cursorColor, + ), + ), + ), + ), + )); + final RenderEditable renderObject = tester.allRenderObjects.whereType().first; + expect(renderObject.textHeightBehavior, equals(customTextHeightBehavior)); + }); + + testWidgets('EditableText defaultTextHeightBehavior is used over inherited widget', (WidgetTester tester) async { + const TextHeightBehavior inheritedTextHeightBehavior = TextHeightBehavior( + applyHeightToLastDescent: true, + applyHeightToFirstAscent: false, + ); + const TextHeightBehavior customTextHeightBehavior = TextHeightBehavior( + applyHeightToLastDescent: false, + applyHeightToFirstAscent: false, + ); + await tester.pumpWidget(MediaQuery( + data: const MediaQueryData(devicePixelRatio: 1.0), + child: Directionality( + textDirection: TextDirection.ltr, + child: FocusScope( + node: focusScopeNode, + autofocus: true, + child: DefaultTextHeightBehavior( + textHeightBehavior: inheritedTextHeightBehavior, + child: EditableText( + backgroundCursorColor: Colors.grey, + controller: controller, + focusNode: focusNode, + style: textStyle, + cursorColor: cursorColor, + textHeightBehavior: customTextHeightBehavior, + ), + ), + ), + ), + )); + final RenderEditable renderObject = tester.allRenderObjects.whereType().first; + expect(renderObject.textHeightBehavior, isNot(equals(inheritedTextHeightBehavior))); + expect(renderObject.textHeightBehavior, equals(customTextHeightBehavior)); + }); } class MockTextFormatter extends TextInputFormatter {