Commit 12d5b26c authored by Matt Perry's avatar Matt Perry Committed by GitHub

Add an onChanged callback to InputFormField. (#7398)

Fixes https://github.com/flutter/flutter/issues/7210
parent 7c9f9be3
...@@ -629,6 +629,7 @@ class InputFormField extends FormField<InputValue> { ...@@ -629,6 +629,7 @@ class InputFormField extends FormField<InputValue> {
InputValue initialValue: InputValue.empty, InputValue initialValue: InputValue.empty,
FormFieldSetter<InputValue> onSaved, FormFieldSetter<InputValue> onSaved,
FormFieldValidator<InputValue> validator, FormFieldValidator<InputValue> validator,
ValueChanged<InputValue> onChanged,
}) : super( }) : super(
key: key, key: key,
initialValue: initialValue, initialValue: initialValue,
...@@ -647,7 +648,11 @@ class InputFormField extends FormField<InputValue> { ...@@ -647,7 +648,11 @@ class InputFormField extends FormField<InputValue> {
autofocus: autofocus, autofocus: autofocus,
maxLines: maxLines, maxLines: maxLines,
value: field.value, value: field.value,
onChanged: field.onChanged, onChanged: (InputValue value) {
field.onChanged(value);
if (onChanged != null)
onChanged(value);
},
errorText: field.errorText, errorText: field.errorText,
); );
}, },
......
...@@ -54,6 +54,37 @@ void main() { ...@@ -54,6 +54,37 @@ void main() {
await checkText(''); await checkText('');
}); });
testWidgets('onChanged callback is called', (WidgetTester tester) async {
String fieldValue;
Widget builder() {
return new Center(
child: new Material(
child: new Form(
child: new InputFormField(
onChanged: (InputValue value) { fieldValue = value.text; },
),
)
)
);
}
await tester.pumpWidget(builder());
await showKeyboard(tester);
expect(fieldValue, isNull);
Future<Null> checkText(String testValue) async {
enterText(testValue);
await tester.idle();
// pump'ing is unnecessary because callback happens regardless of frames
expect(fieldValue, equals(testValue));
}
await checkText('Test');
await checkText('');
});
testWidgets('Validator sets the error text only when validate is called', (WidgetTester tester) async { testWidgets('Validator sets the error text only when validate is called', (WidgetTester tester) async {
GlobalKey<FormState> formKey = new GlobalKey<FormState>(); GlobalKey<FormState> formKey = new GlobalKey<FormState>();
GlobalKey inputKey = new GlobalKey(); GlobalKey inputKey = new GlobalKey();
......
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