Unverified Commit f0a4eab7 authored by Christian Mürtz's avatar Christian Mürtz Committed by GitHub

Make TextFormFieldState.didChange change text fields value (#54481)

parent 98651c02
......@@ -309,6 +309,14 @@ class _TextFormFieldState extends FormFieldState<String> {
super.dispose();
}
@override
void didChange(String value) {
super.didChange(value);
if (_effectiveController.text != value)
_effectiveController.text = value;
}
@override
void reset() {
super.reset();
......
......@@ -331,4 +331,50 @@ void main() {
await tester.pump(const Duration(milliseconds: 300));
expect(tapCount, 3);
});
// Regression test for https://github.com/flutter/flutter/issues/54472.
testWidgets('reset resets the text fields value to the initialValue', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: TextFormField(
initialValue: 'initialValue',
),
),
),
)
);
await tester.enterText(find.byType(TextFormField), 'changedValue');
final FormFieldState<String> state = tester.state<FormFieldState<String>>(find.byType(TextFormField));
state.reset();
expect(find.text('changedValue'), findsNothing);
expect(find.text('initialValue'), findsOneWidget);
});
// Regression test for https://github.com/flutter/flutter/issues/54472.
testWidgets('didChange changes text fields value', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: TextFormField(
initialValue: 'initialValue',
),
),
),
)
);
expect(find.text('initialValue'), findsOneWidget);
final FormFieldState<String> state = tester.state<FormFieldState<String>>(find.byType(TextFormField));
state.didChange('changedValue');
expect(find.text('initialValue'), findsNothing);
expect(find.text('changedValue'), findsOneWidget);
});
}
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