Commit b6349e7d authored by Kasper's avatar Kasper Committed by LongCatIsLooong

Added onChanged property to TextFormField (#34932)

parent 883d6ead
...@@ -98,6 +98,7 @@ class TextFormField extends FormField<String> { ...@@ -98,6 +98,7 @@ class TextFormField extends FormField<String> {
int minLines, int minLines,
bool expands = false, bool expands = false,
int maxLength, int maxLength,
ValueChanged<String> onChanged,
VoidCallback onEditingComplete, VoidCallback onEditingComplete,
ValueChanged<String> onFieldSubmitted, ValueChanged<String> onFieldSubmitted,
FormFieldSetter<String> onSaved, FormFieldSetter<String> onSaved,
...@@ -144,6 +145,12 @@ class TextFormField extends FormField<String> { ...@@ -144,6 +145,12 @@ class TextFormField extends FormField<String> {
final _TextFormFieldState state = field; final _TextFormFieldState state = field;
final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration()) final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration())
.applyDefaults(Theme.of(field.context).inputDecorationTheme); .applyDefaults(Theme.of(field.context).inputDecorationTheme);
void onChangedHandler(String value) {
if (onChanged != null) {
onChanged(value);
}
field.didChange(value);
}
return TextField( return TextField(
controller: state._effectiveController, controller: state._effectiveController,
focusNode: focusNode, focusNode: focusNode,
...@@ -165,7 +172,7 @@ class TextFormField extends FormField<String> { ...@@ -165,7 +172,7 @@ class TextFormField extends FormField<String> {
minLines: minLines, minLines: minLines,
expands: expands, expands: expands,
maxLength: maxLength, maxLength: maxLength,
onChanged: field.didChange, onChanged: onChangedHandler,
onEditingComplete: onEditingComplete, onEditingComplete: onEditingComplete,
onSubmitted: onFieldSubmitted, onSubmitted: onFieldSubmitted,
inputFormatters: inputFormatters, inputFormatters: inputFormatters,
......
...@@ -123,6 +123,28 @@ void main() { ...@@ -123,6 +123,28 @@ void main() {
expect(_called, true); 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 { testWidgets('autovalidate is passed to super', (WidgetTester tester) async {
int _validateCalled = 0; int _validateCalled = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment