Unverified Commit adc64827 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Implement CupertinoDatepicker time/dateTime constraints (#44628)

parent a3bbdfb2
......@@ -661,7 +661,7 @@ void main() {
});
testWidgets(
'picker automatically scrolls away from invalid date, '
'date picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates",
(WidgetTester tester) async {
DateTime date;
......@@ -727,6 +727,160 @@ void main() {
);
});
testWidgets(
'dateTime picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates",
(WidgetTester tester) async {
DateTime date;
final DateTime minimum = DateTime(2019, 11, 11, 3, 30);
final DateTime maximum = DateTime(2019, 11, 11, 14, 59, 59);
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: SizedBox(
height: 400.0,
width: 400.0,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.dateAndTime,
minimumDate: minimum,
maximumDate: maximum,
onDateTimeChanged: (DateTime newDate) {
date = newDate;
// Callback doesn't transiently go into invalid dates.
expect(minimum.isAfter(newDate), isFalse);
expect(maximum.isBefore(newDate), isFalse);
},
initialDateTime: DateTime(2019, 11, 11, 4),
),
),
),
),
);
// 3:00 is valid but 2:00 should be invalid.
expect(
tester.widget<Text>(find.text('3')).style.color,
isNot(isSameColorAs(CupertinoColors.inactiveGray.color)),
);
expect(
tester.widget<Text>(find.text('2')).style.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
// 'PM' is greyed out.
expect(
tester.widget<Text>(find.text('PM')).style.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
await tester.drag(find.text('AM'), const Offset(0.0, -32.0), touchSlopY: 0.0);
await tester.pump();
await tester.pumpAndSettle(); // Now the autoscrolling should happen.
expect(
date,
DateTime(2019, 11, 11, 14, 59),
);
// 3'o clock and 'AM' are now greyed out.
expect(
tester.widget<Text>(find.text('AM')).style.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
expect(
tester.widget<Text>(find.text('3')).style.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
await tester.drag(find.text('PM'), const Offset(0.0, 32.0), touchSlopY: 0.0);
await tester.pump(); // Once to trigger the post frame animate call.
await tester.pumpAndSettle();
// Returns to min date.
expect(
date,
DateTime(2019, 11, 11, 3, 30),
);
});
testWidgets(
'time picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates",
(WidgetTester tester) async {
DateTime date;
final DateTime minimum = DateTime(2019, 11, 11, 3, 30);
final DateTime maximum = DateTime(2019, 11, 11, 14, 59, 59);
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: SizedBox(
height: 400.0,
width: 400.0,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.time,
minimumDate: minimum,
maximumDate: maximum,
onDateTimeChanged: (DateTime newDate) {
date = newDate;
// Callback doesn't transiently go into invalid dates.
expect(minimum.isAfter(newDate), isFalse);
expect(maximum.isBefore(newDate), isFalse);
},
initialDateTime: DateTime(2019, 11, 11, 4),
),
),
),
),
);
// 3:00 is valid but 2:00 should be invalid.
expect(
tester.widget<Text>(find.text('3')).style.color,
isNot(isSameColorAs(CupertinoColors.inactiveGray.color)),
);
expect(
tester.widget<Text>(find.text('2')).style.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
// 'PM' is greyed out.
expect(
tester.widget<Text>(find.text('PM')).style.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
await tester.drag(find.text('AM'), const Offset(0.0, -32.0), touchSlopY: 0.0);
await tester.pump();
await tester.pumpAndSettle(); // Now the autoscrolling should happen.
expect(
date,
DateTime(2019, 11, 11, 14, 59),
);
// 3'o clock and 'AM' are now greyed out.
expect(
tester.widget<Text>(find.text('AM')).style.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
expect(
tester.widget<Text>(find.text('3')).style.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
await tester.drag(find.text('PM'), const Offset(0.0, 32.0), touchSlopY: 0.0);
await tester.pump(); // Once to trigger the post frame animate call.
await tester.pumpAndSettle();
// Returns to min date.
expect(
date,
DateTime(2019, 11, 11, 3, 30),
);
});
testWidgets('picker automatically scrolls away from invalid date on day change', (WidgetTester tester) async {
DateTime date;
await tester.pumpWidget(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment