diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 6b8ba72b7a..952e55ecc2 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -106,6 +106,7 @@ class TextField extends StatefulWidget { this.textCapitalization = TextCapitalization.none, this.style, this.textAlign = TextAlign.start, + this.textDirection, this.autofocus = false, this.obscureText = false, this.autocorrect = true, @@ -176,6 +177,9 @@ class TextField extends StatefulWidget { /// {@macro flutter.widgets.editableText.textAlign} final TextAlign textAlign; + /// {@macro flutter.widgets.editableText.textDirection} + final TextDirection textDirection; + /// {@macro flutter.widgets.editableText.autofocus} final bool autofocus; @@ -508,6 +512,7 @@ class _TextFieldState extends State with AutomaticKeepAliveClientMixi textCapitalization: widget.textCapitalization, style: style, textAlign: widget.textAlign, + textDirection: widget.textDirection, autofocus: widget.autofocus, obscureText: widget.obscureText, autocorrect: widget.autocorrect, diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index 7934d4adf9..3380712204 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -58,6 +58,7 @@ class TextFormField extends FormField { TextCapitalization textCapitalization = TextCapitalization.none, TextInputAction textInputAction, TextStyle style, + TextDirection textDirection, TextAlign textAlign = TextAlign.start, bool autofocus = false, bool obscureText = false, @@ -105,6 +106,7 @@ class TextFormField extends FormField { textInputAction: textInputAction, style: style, textAlign: textAlign, + textDirection: textDirection, textCapitalization: textCapitalization, autofocus: autofocus, obscureText: obscureText, diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 5fa444b739..cea7e855de 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -269,6 +269,7 @@ class EditableText extends StatefulWidget { /// {@endtemplate} final TextAlign textAlign; + /// {@template flutter.widgets.editableText.textDirection} /// The directionality of the text. /// /// This decides how [textAlign] values like [TextAlign.start] and @@ -282,6 +283,7 @@ class EditableText extends StatefulWidget { /// its left. /// /// Defaults to the ambient [Directionality], if any. + /// {@endtemplate} final TextDirection textDirection; /// {@template flutter.widgets.editableText.textCapitalization} diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index a73ea0caea..1dfe8344f5 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -2928,6 +2928,48 @@ void main() { expect(focusNode.hasFocus, isFalse); }); + testWidgets('TextField displays text with text direction', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Material( + child: TextField( + textDirection: TextDirection.rtl, + ), + ), + ), + ); + + RenderEditable editable = findRenderEditable(tester); + + await tester.enterText(find.byType(TextField), '0123456789101112'); + await tester.pumpAndSettle(); + Offset topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 10)).topLeft, + ); + + expect(topLeft.dx, equals(701.0)); + + await tester.pumpWidget( + const MaterialApp( + home: Material( + child: TextField( + textDirection: TextDirection.ltr, + ), + ), + ), + ); + + editable = findRenderEditable(tester); + + await tester.enterText(find.byType(TextField), '0123456789101112'); + await tester.pumpAndSettle(); + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 10)).topLeft, + ); + + expect(topLeft.dx, equals(160.0)); + }); + testWidgets('TextField semantics', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); final TextEditingController controller = TextEditingController();