diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index f45c89c8ee..8cc9e290cf 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -251,6 +251,7 @@ class CupertinoTextField extends StatefulWidget { this.strutStyle, this.textAlign = TextAlign.start, this.textAlignVertical, + this.textDirection, this.readOnly = false, ToolbarOptions? toolbarOptions, this.showCursor, @@ -404,6 +405,7 @@ class CupertinoTextField extends StatefulWidget { this.strutStyle, this.textAlign = TextAlign.start, this.textAlignVertical, + this.textDirection, this.readOnly = false, ToolbarOptions? toolbarOptions, this.showCursor, @@ -608,6 +610,9 @@ class CupertinoTextField extends StatefulWidget { /// {@macro flutter.material.InputDecorator.textAlignVertical} final TextAlignVertical? textAlignVertical; + /// {@macro flutter.widgets.editableText.textDirection} + final TextDirection? textDirection; + /// {@macro flutter.widgets.editableText.readOnly} final bool readOnly; @@ -819,6 +824,7 @@ class CupertinoTextField extends StatefulWidget { properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); properties.add(EnumProperty('textAlign', textAlign, defaultValue: TextAlign.start)); properties.add(DiagnosticsProperty('textAlignVertical', textAlignVertical, defaultValue: null)); + properties.add(EnumProperty('textDirection', textDirection, defaultValue: null)); } } @@ -1176,6 +1182,7 @@ class _CupertinoTextFieldState extends State with Restoratio style: textStyle, strutStyle: widget.strutStyle, textAlign: widget.textAlign, + textDirection: widget.textDirection, autofocus: widget.autofocus, obscuringCharacter: widget.obscuringCharacter, obscureText: widget.obscureText, diff --git a/packages/flutter/lib/src/cupertino/text_form_field_row.dart b/packages/flutter/lib/src/cupertino/text_form_field_row.dart index 8a5de319a0..dbab69686c 100644 --- a/packages/flutter/lib/src/cupertino/text_form_field_row.dart +++ b/packages/flutter/lib/src/cupertino/text_form_field_row.dart @@ -144,6 +144,7 @@ class CupertinoTextFormFieldRow extends FormField { TextInputAction? textInputAction, TextStyle? style, StrutStyle? strutStyle, + TextDirection? textDirection, TextAlign textAlign = TextAlign.start, TextAlignVertical? textAlignVertical, bool autofocus = false, @@ -238,6 +239,7 @@ class CupertinoTextFormFieldRow extends FormField { textAlign: textAlign, textAlignVertical: textAlignVertical, textCapitalization: textCapitalization, + textDirection: textDirection, autofocus: autofocus, toolbarOptions: toolbarOptions, readOnly: readOnly, diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index feccf73253..3acb126444 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -4779,4 +4779,32 @@ void main() { expect(disabledColor, isSameColorAs(const Color(0xFFFAFAFA))); }, ); + + testWidgets('textDirection is passed to EditableText', (WidgetTester tester) async { + await tester.pumpWidget( + const CupertinoApp( + home: Center( + child: CupertinoTextField( + textDirection: TextDirection.ltr, + ), + ), + ), + ); + + final EditableText ltrWidget = tester.widget(find.byType(EditableText)); + expect(ltrWidget.textDirection, TextDirection.ltr); + + await tester.pumpWidget( + const CupertinoApp( + home: Center( + child: CupertinoTextField( + textDirection: TextDirection.rtl, + ), + ), + ), + ); + + final EditableText rtlWidget = tester.widget(find.byType(EditableText)); + expect(rtlWidget.textDirection, TextDirection.rtl); + }); } diff --git a/packages/flutter/test/cupertino/text_form_field_row_test.dart b/packages/flutter/test/cupertino/text_form_field_row_test.dart index 0e5aabadce..691e3e9a95 100644 --- a/packages/flutter/test/cupertino/text_form_field_row_test.dart +++ b/packages/flutter/test/cupertino/text_form_field_row_test.dart @@ -458,4 +458,38 @@ void main() { final Text errorText = tester.widget(errorTextFinder); expect(errorText.data, 'Enter Value'); }); + + testWidgets('Passes textDirection to underlying CupertinoTextField', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoTextFormFieldRow( + textDirection: TextDirection.ltr, + ), + ), + ), + ); + + final Finder ltrTextFieldFinder = find.byType(CupertinoTextField); + expect(ltrTextFieldFinder, findsOneWidget); + + final CupertinoTextField ltrTextFieldWidget = tester.widget(ltrTextFieldFinder); + expect(ltrTextFieldWidget.textDirection, TextDirection.ltr); + + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoTextFormFieldRow( + textDirection: TextDirection.rtl, + ), + ), + ), + ); + + final Finder rtlTextFieldFinder = find.byType(CupertinoTextField); + expect(rtlTextFieldFinder, findsOneWidget); + + final CupertinoTextField rtlTextFieldWidget = tester.widget(rtlTextFieldFinder); + expect(rtlTextFieldWidget.textDirection, TextDirection.rtl); + }); }