Unverified Commit 0220c358 authored by YeungKC's avatar YeungKC Committed by GitHub

Fix FormFieldState value not in sync with the onChanged value from TextFormField. (#65695)

parent b2b5f263
......@@ -232,10 +232,10 @@ class TextFormField extends FormField<String> {
final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration())
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
void onChangedHandler(String value) {
field.didChange(value);
if (onChanged != null) {
onChanged(value);
}
field.didChange(value);
}
return TextField(
controller: state._effectiveController,
......
......@@ -431,6 +431,33 @@ void main() {
expect(find.text('changedValue'), findsOneWidget);
});
testWidgets('onChanged callbacks value and FormFieldState.value are sync', (WidgetTester tester) async {
bool _called = false;
FormFieldState<String> state;
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: TextFormField(
onChanged: (String value) {
_called = true;
expect(value, state.value);
},
),
),
),
),
);
state = tester.state<FormFieldState<String>>(find.byType(TextFormField));
await tester.enterText(find.byType(TextField), 'Soup');
expect(_called, true);
});
testWidgets('autofillHints is passed to super', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
......
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