Skip to content

Commit eed471e

Browse files
fredriksHixie
authored andcommitted
Expose textAlign on TextFormField (flutter#13414)
* Expose textAlign on TextFormField Fixes flutter#11404 * Added name to AUTHORS * Added a test for TextFormWidget's textAlign
1 parent 0ca1af7 commit eed471e

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ Mike Hoolehan <mike@hoolehan.com>
1818
German Saprykin <saprykin.h@gmail.com>
1919
Stefano Rodriguez <hlsroddy@gmail.com>
2020
Yusuke Konishi <yahpeycoy0403@gmail.com>
21+
Fredrik Simón <fredrik@fsimon.net>

packages/flutter/lib/src/material/text_form_field.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TextFormField extends FormField<String> {
4848
InputDecoration decoration: const InputDecoration(),
4949
TextInputType keyboardType: TextInputType.text,
5050
TextStyle style,
51+
TextAlign textAlign: TextAlign.start,
5152
bool autofocus: false,
5253
bool obscureText: false,
5354
bool autocorrect: true,
@@ -57,6 +58,7 @@ class TextFormField extends FormField<String> {
5758
List<TextInputFormatter> inputFormatters,
5859
}) : assert(initialValue != null),
5960
assert(keyboardType != null),
61+
assert(textAlign != null),
6062
assert(autofocus != null),
6163
assert(obscureText != null),
6264
assert(autocorrect != null),
@@ -74,6 +76,7 @@ class TextFormField extends FormField<String> {
7476
decoration: decoration.copyWith(errorText: field.errorText),
7577
keyboardType: keyboardType,
7678
style: style,
79+
textAlign: textAlign,
7780
autofocus: autofocus,
7881
obscureText: obscureText,
7982
autocorrect: autocorrect,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
8+
void main() {
9+
testWidgets('Passes textAlign to underlying TextField', (WidgetTester tester) async {
10+
const TextAlign alignment = TextAlign.center;
11+
12+
await tester.pumpWidget(
13+
new MaterialApp(
14+
home: new Material(
15+
child: new Center(
16+
child: new TextFormField(
17+
textAlign: alignment,
18+
),
19+
),
20+
),
21+
),
22+
);
23+
24+
final Finder textFieldFinder = find.byType(TextField);
25+
expect(textFieldFinder, findsOneWidget);
26+
27+
final TextField textFieldWidget = tester.widget(textFieldFinder);
28+
expect(textFieldWidget.textAlign, alignment);
29+
});
30+
}

0 commit comments

Comments
 (0)