@@ -49,6 +49,7 @@ void main() {
49
49
Key ? formKey,
50
50
ThemeData ? theme,
51
51
Iterable <LocalizationsDelegate <dynamic >>? localizationsDelegates,
52
+ bool acceptEmptyDate = false ,
52
53
}) {
53
54
return MaterialApp (
54
55
theme: theme ?? ThemeData .from (colorScheme: const ColorScheme .light ()),
@@ -69,6 +70,7 @@ void main() {
69
70
fieldHintText: fieldHintText,
70
71
fieldLabelText: fieldLabelText,
71
72
autofocus: autofocus,
73
+ acceptEmptyDate: acceptEmptyDate,
72
74
),
73
75
),
74
76
),
@@ -345,5 +347,34 @@ void main() {
345
347
)
346
348
);
347
349
});
350
+
351
+ testWidgets ('when an empty date is entered and acceptEmptyDate is true, then errorFormatText is not shown' , (WidgetTester tester) async {
352
+ final GlobalKey <FormState > formKey = GlobalKey <FormState >();
353
+ const String errorFormatText = 'That is not a date.' ;
354
+ await tester.pumpWidget (inputDatePickerField (
355
+ errorFormatText: errorFormatText,
356
+ formKey: formKey,
357
+ acceptEmptyDate: true ,
358
+ ));
359
+ await tester.enterText (find.byType (TextField ), '' );
360
+ await tester.pumpAndSettle ();
361
+ formKey.currentState! .validate ();
362
+ await tester.pumpAndSettle ();
363
+ expect (find.text (errorFormatText), findsNothing);
364
+ });
365
+
366
+ testWidgets ('when an empty date is entered and acceptEmptyDate is false, then errorFormatText is shown' , (WidgetTester tester) async {
367
+ final GlobalKey <FormState > formKey = GlobalKey <FormState >();
368
+ const String errorFormatText = 'That is not a date.' ;
369
+ await tester.pumpWidget (inputDatePickerField (
370
+ errorFormatText: errorFormatText,
371
+ formKey: formKey,
372
+ ));
373
+ await tester.enterText (find.byType (TextField ), '' );
374
+ await tester.pumpAndSettle ();
375
+ formKey.currentState! .validate ();
376
+ await tester.pumpAndSettle ();
377
+ expect (find.text (errorFormatText), findsOneWidget);
378
+ });
348
379
});
349
380
}
0 commit comments