fix(cupertinoDatePicker): do not display previous day when minimumDate is midnight (#72933)

This commit is contained in:
David LJ 2021-01-07 19:34:03 +01:00 committed by GitHub
parent 925ff2dcb1
commit 84ddffb36b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -705,7 +705,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
final DateTime now = DateTime.now();
if (widget.minimumDate?.isAfter(rangeEnd) == true)
if (widget.minimumDate?.isBefore(rangeEnd) == false)
return null;
if (widget.maximumDate?.isAfter(rangeStart) == false)
return null;

View File

@ -933,6 +933,29 @@ void main() {
expect(date.day, minDate.day);
});
testWidgets('date picker does not display previous day of minimumDate if it is set at midnight', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/72932
final DateTime minDate = DateTime(2019, 12, 31);
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: SizedBox(
height: 400.0,
width: 400.0,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.dateAndTime,
minimumDate: minDate,
onDateTimeChanged: (DateTime newDate) { },
initialDateTime: minDate.add(const Duration(days: 1)),
),
),
),
),
);
expect(find.text('Mon Dec 30'), findsNothing);
});
group('Picker handles initial noon/midnight times', () {
testWidgets('midnight', (WidgetTester tester) async {