Reset autovalidate in the text input form field of the Date Picker when switching back to input mode from calendar mode. (#53434)

This commit is contained in:
Darren Austin 2020-03-27 15:06:01 -07:00 committed by GitHub
parent 8ce6f05c50
commit 4dd9136397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -296,6 +296,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
setState(() { setState(() {
switch (_entryMode) { switch (_entryMode) {
case DatePickerEntryMode.calendar: case DatePickerEntryMode.calendar:
_autoValidate = false;
_entryMode = DatePickerEntryMode.input; _entryMode = DatePickerEntryMode.input;
break; break;
case DatePickerEntryMode.input: case DatePickerEntryMode.input:

View File

@ -136,6 +136,30 @@ void main() {
}); });
}); });
testWidgets('Switching to input mode resets input error state', (WidgetTester tester) async {
await prepareDatePicker(tester, (Future<DateTime> date) async {
// Enter text input mode and type an invalid date to get error.
await tester.tap(find.byIcon(Icons.edit));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), '1234567');
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();
expect(find.text('Invalid format.'), findsOneWidget);
// Toggle to calender mode and then back to input mode
await tester.tap(find.byIcon(Icons.calendar_today));
await tester.pumpAndSettle();
await tester.tap(find.byIcon(Icons.edit));
await tester.pumpAndSettle();
expect(find.text('Invalid format.'), findsNothing);
// Edit the text, the error should not be showing until ok is tapped
await tester.enterText(find.byType(TextField), '1234567');
await tester.pumpAndSettle();
expect(find.text('Invalid format.'), findsNothing);
});
});
testWidgets('builder parameter', (WidgetTester tester) async { testWidgets('builder parameter', (WidgetTester tester) async {
Widget buildFrame(TextDirection textDirection) { Widget buildFrame(TextDirection textDirection) {
return MaterialApp( return MaterialApp(