Unverified Commit 503ae8cb authored by jslavitz's avatar jslavitz Committed by GitHub

Adds Text Direction functionality to the TextField (#23609)

* added textDirection to TextField
parent 419be223
...@@ -106,6 +106,7 @@ class TextField extends StatefulWidget { ...@@ -106,6 +106,7 @@ class TextField extends StatefulWidget {
this.textCapitalization = TextCapitalization.none, this.textCapitalization = TextCapitalization.none,
this.style, this.style,
this.textAlign = TextAlign.start, this.textAlign = TextAlign.start,
this.textDirection,
this.autofocus = false, this.autofocus = false,
this.obscureText = false, this.obscureText = false,
this.autocorrect = true, this.autocorrect = true,
...@@ -176,6 +177,9 @@ class TextField extends StatefulWidget { ...@@ -176,6 +177,9 @@ class TextField extends StatefulWidget {
/// {@macro flutter.widgets.editableText.textAlign} /// {@macro flutter.widgets.editableText.textAlign}
final TextAlign textAlign; final TextAlign textAlign;
/// {@macro flutter.widgets.editableText.textDirection}
final TextDirection textDirection;
/// {@macro flutter.widgets.editableText.autofocus} /// {@macro flutter.widgets.editableText.autofocus}
final bool autofocus; final bool autofocus;
...@@ -508,6 +512,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -508,6 +512,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
textCapitalization: widget.textCapitalization, textCapitalization: widget.textCapitalization,
style: style, style: style,
textAlign: widget.textAlign, textAlign: widget.textAlign,
textDirection: widget.textDirection,
autofocus: widget.autofocus, autofocus: widget.autofocus,
obscureText: widget.obscureText, obscureText: widget.obscureText,
autocorrect: widget.autocorrect, autocorrect: widget.autocorrect,
......
...@@ -58,6 +58,7 @@ class TextFormField extends FormField<String> { ...@@ -58,6 +58,7 @@ class TextFormField extends FormField<String> {
TextCapitalization textCapitalization = TextCapitalization.none, TextCapitalization textCapitalization = TextCapitalization.none,
TextInputAction textInputAction, TextInputAction textInputAction,
TextStyle style, TextStyle style,
TextDirection textDirection,
TextAlign textAlign = TextAlign.start, TextAlign textAlign = TextAlign.start,
bool autofocus = false, bool autofocus = false,
bool obscureText = false, bool obscureText = false,
...@@ -105,6 +106,7 @@ class TextFormField extends FormField<String> { ...@@ -105,6 +106,7 @@ class TextFormField extends FormField<String> {
textInputAction: textInputAction, textInputAction: textInputAction,
style: style, style: style,
textAlign: textAlign, textAlign: textAlign,
textDirection: textDirection,
textCapitalization: textCapitalization, textCapitalization: textCapitalization,
autofocus: autofocus, autofocus: autofocus,
obscureText: obscureText, obscureText: obscureText,
......
...@@ -269,6 +269,7 @@ class EditableText extends StatefulWidget { ...@@ -269,6 +269,7 @@ class EditableText extends StatefulWidget {
/// {@endtemplate} /// {@endtemplate}
final TextAlign textAlign; final TextAlign textAlign;
/// {@template flutter.widgets.editableText.textDirection}
/// The directionality of the text. /// The directionality of the text.
/// ///
/// This decides how [textAlign] values like [TextAlign.start] and /// This decides how [textAlign] values like [TextAlign.start] and
...@@ -282,6 +283,7 @@ class EditableText extends StatefulWidget { ...@@ -282,6 +283,7 @@ class EditableText extends StatefulWidget {
/// its left. /// its left.
/// ///
/// Defaults to the ambient [Directionality], if any. /// Defaults to the ambient [Directionality], if any.
/// {@endtemplate}
final TextDirection textDirection; final TextDirection textDirection;
/// {@template flutter.widgets.editableText.textCapitalization} /// {@template flutter.widgets.editableText.textCapitalization}
......
...@@ -2928,6 +2928,48 @@ void main() { ...@@ -2928,6 +2928,48 @@ void main() {
expect(focusNode.hasFocus, isFalse); 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 { testWidgets('TextField semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final TextEditingController controller = TextEditingController(); final TextEditingController controller = TextEditingController();
......
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