From cdc68a73e6a89ae7eb4f24517b0d30eb031a9aa8 Mon Sep 17 00:00:00 2001 From: Roberto Scaramuzzi Date: Mon, 9 Apr 2018 13:43:43 -0700 Subject: [PATCH] Update text_form_field.dart (#15843) * Update text_form_field.dart * Update text_form_field_test.dart * Update text_form_field_test.dart * Update text_form_field_test.dart --- .../lib/src/material/text_form_field.dart | 3 +++ .../test/material/text_form_field_test.dart | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index 86de88caa17..0181c552c57 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -60,6 +60,7 @@ class TextFormField extends FormField { bool autofocus: false, bool obscureText: false, bool autocorrect: true, + bool autovalidate: false, bool maxLengthEnforced: true, int maxLines: 1, int maxLength, @@ -74,6 +75,7 @@ class TextFormField extends FormField { assert(autofocus != null), assert(obscureText != null), assert(autocorrect != null), + assert(autovalidate != null), assert(maxLengthEnforced != null), assert(maxLines == null || maxLines > 0), assert(maxLength == null || maxLength > 0), @@ -82,6 +84,7 @@ class TextFormField extends FormField { initialValue: controller != null ? controller.text : (initialValue ?? ''), onSaved: onSaved, validator: validator, + autovalidate: autovalidate, builder: (FormFieldState field) { final _TextFormFieldState state = field; final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration()) diff --git a/packages/flutter/test/material/text_form_field_test.dart b/packages/flutter/test/material/text_form_field_test.dart index 921905dd757..872455ce014 100644 --- a/packages/flutter/test/material/text_form_field_test.dart +++ b/packages/flutter/test/material/text_form_field_test.dart @@ -49,4 +49,27 @@ void main() { await tester.pump(); expect(_called, true); }); + + testWidgets('autovalidate is passed to super', (WidgetTester tester) async { + int _validateCalled = 0; + + await tester.pumpWidget( + new MaterialApp( + home: new Material( + child: new Center( + child: new TextFormField( + autovalidate: true, + validator: (String value) { _validateCalled++; return null; }, + ), + ), + ), + ), + ); + + expect(_validateCalled, 1); + await tester.showKeyboard(find.byType(TextField)); + await tester.enterText(find.byType(TextField), 'a'); + await tester.pump(); + expect(_validateCalled, 2); + }); }