Adds Text Direction functionality to the TextField (#23609)
* added textDirection to TextField
This commit is contained in:
parent
419be22340
commit
503ae8cbfd
@ -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<TextField> with AutomaticKeepAliveClientMixi
|
||||
textCapitalization: widget.textCapitalization,
|
||||
style: style,
|
||||
textAlign: widget.textAlign,
|
||||
textDirection: widget.textDirection,
|
||||
autofocus: widget.autofocus,
|
||||
obscureText: widget.obscureText,
|
||||
autocorrect: widget.autocorrect,
|
||||
|
@ -58,6 +58,7 @@ class TextFormField extends FormField<String> {
|
||||
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<String> {
|
||||
textInputAction: textInputAction,
|
||||
style: style,
|
||||
textAlign: textAlign,
|
||||
textDirection: textDirection,
|
||||
textCapitalization: textCapitalization,
|
||||
autofocus: autofocus,
|
||||
obscureText: obscureText,
|
||||
|
@ -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}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user