From b6349e7d9ab011d392fee753374ef2cc8d910947 Mon Sep 17 00:00:00 2001 From: Kasper Date: Thu, 27 Jun 2019 03:13:53 +0200 Subject: [PATCH] Added onChanged property to TextFormField (#34932) --- .../lib/src/material/text_form_field.dart | 9 +++++++- .../test/material/text_form_field_test.dart | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index f111b77a5d..cea1bf95a7 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -98,6 +98,7 @@ class TextFormField extends FormField { int minLines, bool expands = false, int maxLength, + ValueChanged onChanged, VoidCallback onEditingComplete, ValueChanged onFieldSubmitted, FormFieldSetter onSaved, @@ -144,6 +145,12 @@ class TextFormField extends FormField { final _TextFormFieldState state = field; final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration()) .applyDefaults(Theme.of(field.context).inputDecorationTheme); + void onChangedHandler(String value) { + if (onChanged != null) { + onChanged(value); + } + field.didChange(value); + } return TextField( controller: state._effectiveController, focusNode: focusNode, @@ -165,7 +172,7 @@ class TextFormField extends FormField { minLines: minLines, expands: expands, maxLength: maxLength, - onChanged: field.didChange, + onChanged: onChangedHandler, onEditingComplete: onEditingComplete, onSubmitted: onFieldSubmitted, inputFormatters: inputFormatters, diff --git a/packages/flutter/test/material/text_form_field_test.dart b/packages/flutter/test/material/text_form_field_test.dart index 8fefc4482b..8fe21d68ba 100644 --- a/packages/flutter/test/material/text_form_field_test.dart +++ b/packages/flutter/test/material/text_form_field_test.dart @@ -123,6 +123,28 @@ void main() { expect(_called, true); }); + testWidgets('onChanged callbacks are called', (WidgetTester tester) async { + String _value; + + await tester.pumpWidget( + MaterialApp( + home: Material( + child: Center( + child: TextFormField( + onChanged: (String value) { + _value = value; + }, + ), + ), + ), + ), + ); + + await tester.enterText(find.byType(TextField), 'Soup'); + await tester.pump(); + expect(_value, 'Soup'); + }); + testWidgets('autovalidate is passed to super', (WidgetTester tester) async { int _validateCalled = 0;