Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Preserve birthday on invalid input

Neeraj Gupta093107af4ad2
diff --git a/mobile/apps/photos/lib/ui/common/date_input.dart b/mobile/apps/photos/lib/ui/common/date_input.dart
index 0fab20e35a..a8592366e7 100644
--- a/mobile/apps/photos/lib/ui/common/date_input.dart
+++ b/mobile/apps/photos/lib/ui/common/date_input.dart
@@ -90,11 +90,15 @@ class _DatePickerFieldState extends State<DatePickerField> {
(widget.lastDate == null || !parsed.isAfter(widget.lastDate!));
setState(() {
- _selectedDate = isValid ? parsed : null;
+ if (isValid) {
+ _selectedDate = parsed;
+ }
_hasError = !isValid;
});
widget.onValidityChanged?.call(isValid);
- widget.onChanged?.call(isValid ? parsed : null);
+ if (isValid) {
+ widget.onChanged?.call(parsed);
+ }
}
Future<void> _showDatePicker() async {
diff --git a/mobile/apps/photos/test/ui/common/date_input_test.dart b/mobile/apps/photos/test/ui/common/date_input_test.dart
index c50619e793..12101a1fda 100644
--- a/mobile/apps/photos/test/ui/common/date_input_test.dart
+++ b/mobile/apps/photos/test/ui/common/date_input_test.dart
@@ -32,12 +32,13 @@ void main() {
await tester.enterText(field, '02/30/2000');
await tester.pump();
- expect(selectedDate, isNull);
+ expect(selectedDate, DateTime(2000, 12, 31));
expect(isValid, isFalse);
expect(find.text('MM/DD/YYYY'), findsOneWidget);
await tester.enterText(field, '');
await tester.pump();
+ expect(selectedDate, isNull);
expect(isValid, isTrue);
expect(find.text('MM/DD/YYYY'), findsNothing);
});