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

This commit is contained in:
Christian Mürtz
2020-04-18 01:58:05 +02:00
committed by GitHub
parent 98651c0252
commit f0a4eab7d7
2 changed files with 54 additions and 0 deletions

View File

@@ -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();

View File

@@ -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);
});
}