forked from firka/flutter
add check for DefaultTextHeightBehavior in EditableText + tests (#59913)
This commit is contained in:
@@ -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<EditableText> 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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<RenderEditable>().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<RenderEditable>().first;
|
||||
expect(renderObject.textHeightBehavior, isNot(equals(inheritedTextHeightBehavior)));
|
||||
expect(renderObject.textHeightBehavior, equals(customTextHeightBehavior));
|
||||
});
|
||||
}
|
||||
|
||||
class MockTextFormatter extends TextInputFormatter {
|
||||
|
||||
Reference in New Issue
Block a user