File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -884,7 +884,12 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
884
884
if (day == null || day < 1 || day > _getDaysInMonth (year, month)) {
885
885
return null ;
886
886
}
887
- return DateTime (year, month, day);
887
+
888
+ try {
889
+ return DateTime (year, month, day);
890
+ } on ArgumentError {
891
+ return null ;
892
+ }
888
893
}
889
894
890
895
@override
Original file line number Diff line number Diff line change @@ -960,6 +960,34 @@ void main() {
960
960
expect (find.text (errorInvalidText! ), findsOneWidget);
961
961
});
962
962
});
963
+
964
+ testWidgets ('Invalid entered text shows error on autovalidate' , (WidgetTester tester) async {
965
+ // This is a regression test for https://github.com/flutter/flutter/issues/126397.
966
+ await prepareDatePicker (tester, (Future <DateTime ?> date) async {
967
+ final TextField field = textField (tester);
968
+ field.controller! .clear ();
969
+
970
+ // Enter some text to trigger autovalidate.
971
+ await tester.enterText (find.byType (TextField ), 'xyz' );
972
+ await tester.tap (find.text ('OK' ));
973
+ await tester.pumpAndSettle ();
974
+
975
+ // Invalid format validation error should be shown.
976
+ expect (find.text ('Invalid format.' ), findsOneWidget);
977
+
978
+ // Clear the text.
979
+ field.controller! .clear ();
980
+
981
+ // Enter an invalid date that is too long while autovalidate is still on.
982
+ await tester.enterText (find.byType (TextField ), '10/05/2023666777889' );
983
+ await tester.pump ();
984
+
985
+ // Invalid format validation error should be shown.
986
+ expect (find.text ('Invalid format.' ), findsOneWidget);
987
+ // Should not throw an exception.
988
+ expect (tester.takeException (), null );
989
+ });
990
+ });
963
991
});
964
992
965
993
group ('Semantics' , () {
Original file line number Diff line number Diff line change @@ -187,4 +187,25 @@ void main() {
187
187
188
188
expect (MaterialLocalizations .of (localizationsAvailable.currentContext! ), isA <MaterialLocalizations >());
189
189
});
190
+
191
+ testWidgets ("parseCompactDate doesn't throw an exception on invalid text" , (WidgetTester tester) async {
192
+ // This is a regression test for https://github.com/flutter/flutter/issues/126397.
193
+ final GlobalKey localizations = GlobalKey ();
194
+
195
+ await tester.pumpWidget (
196
+ MaterialApp (
197
+ home: Material (
198
+ key: localizations,
199
+ child: const SizedBox .expand (),
200
+ ),
201
+ ),
202
+ );
203
+
204
+ final MaterialLocalizations materialLocalizations = MaterialLocalizations .of (localizations.currentContext! );
205
+ expect (materialLocalizations.parseCompactDate ('10/05/2023' ), isNotNull);
206
+ expect (tester.takeException (), null );
207
+
208
+ expect (materialLocalizations.parseCompactDate ('10/05/2023666777889' ), null );
209
+ expect (tester.takeException (), null );
210
+ });
190
211
}
You can’t perform that action at this time.
0 commit comments