From eed471ea3ded5877a2e4627dde8d9c60e251af58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Sim=C3=B3n?= Date: Mon, 11 Dec 2017 22:29:22 +0100 Subject: [PATCH] Expose textAlign on TextFormField (#13414) * Expose textAlign on TextFormField Fixes #11404 * Added name to AUTHORS * Added a test for TextFormWidget's textAlign --- AUTHORS | 1 + .../lib/src/material/text_form_field.dart | 3 ++ .../test/material/text_form_field_test.dart | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 packages/flutter/test/material/text_form_field_test.dart diff --git a/AUTHORS b/AUTHORS index d7e59a9066..3501c548fb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,3 +18,4 @@ Mike Hoolehan German Saprykin Stefano Rodriguez Yusuke Konishi +Fredrik Simón diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index a8ac00e69c..df6e85eff9 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -48,6 +48,7 @@ class TextFormField extends FormField { InputDecoration decoration: const InputDecoration(), TextInputType keyboardType: TextInputType.text, TextStyle style, + TextAlign textAlign: TextAlign.start, bool autofocus: false, bool obscureText: false, bool autocorrect: true, @@ -57,6 +58,7 @@ class TextFormField extends FormField { List inputFormatters, }) : assert(initialValue != null), assert(keyboardType != null), + assert(textAlign != null), assert(autofocus != null), assert(obscureText != null), assert(autocorrect != null), @@ -74,6 +76,7 @@ class TextFormField extends FormField { decoration: decoration.copyWith(errorText: field.errorText), keyboardType: keyboardType, style: style, + textAlign: textAlign, autofocus: autofocus, obscureText: obscureText, autocorrect: autocorrect, diff --git a/packages/flutter/test/material/text_form_field_test.dart b/packages/flutter/test/material/text_form_field_test.dart new file mode 100644 index 0000000000..871e8b9bde --- /dev/null +++ b/packages/flutter/test/material/text_form_field_test.dart @@ -0,0 +1,30 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Passes textAlign to underlying TextField', (WidgetTester tester) async { + const TextAlign alignment = TextAlign.center; + + await tester.pumpWidget( + new MaterialApp( + home: new Material( + child: new Center( + child: new TextFormField( + textAlign: alignment, + ), + ), + ), + ), + ); + + final Finder textFieldFinder = find.byType(TextField); + expect(textFieldFinder, findsOneWidget); + + final TextField textFieldWidget = tester.widget(textFieldFinder); + expect(textFieldWidget.textAlign, alignment); + }); +}