Unverified Commit 9d2f5754 authored by NikosTsesmelis's avatar NikosTsesmelis Committed by GitHub

Cupertino date picker fix for minDate, maxDate when using minuteInterval (#105958)

parent 784388ea
...@@ -946,11 +946,11 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> { ...@@ -946,11 +946,11 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
if (minCheck || maxCheck) { if (minCheck || maxCheck) {
// We have minCheck === !maxCheck. // We have minCheck === !maxCheck.
final DateTime targetDate = minCheck ? widget.minimumDate! : widget.maximumDate!; final DateTime targetDate = minCheck ? widget.minimumDate! : widget.maximumDate!;
_scrollToDate(targetDate, selectedDate); _scrollToDate(targetDate, selectedDate, minCheck);
} }
} }
void _scrollToDate(DateTime newDate, DateTime fromDate) { void _scrollToDate(DateTime newDate, DateTime fromDate, bool minCheck) {
assert(newDate != null); assert(newDate != null);
SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) { SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) {
if (fromDate.year != newDate.year || fromDate.month != newDate.month || fromDate.day != newDate.day) { if (fromDate.year != newDate.year || fromDate.month != newDate.month || fromDate.day != newDate.day) {
...@@ -977,7 +977,9 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> { ...@@ -977,7 +977,9 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
} }
if (fromDate.minute != newDate.minute) { if (fromDate.minute != newDate.minute) {
_animateColumnControllerToItem(minuteController, newDate.minute); final double positionDouble = newDate.minute / widget.minuteInterval;
final int position = minCheck ? positionDouble.ceil() : positionDouble.floor();
_animateColumnControllerToItem(minuteController, position);
} }
}); });
} }
......
...@@ -1601,6 +1601,53 @@ void main() { ...@@ -1601,6 +1601,53 @@ void main() {
// Text style should not return unresolved color. // Text style should not return unresolved color.
expect(paragraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse); expect(paragraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
}); });
testWidgets('TimerPicker minDate - maxDate with minuteInterval', (WidgetTester tester) async {
late DateTime date;
final DateTime minimum = DateTime(2022, 6, 14, 3, 31);
final DateTime initial = DateTime(2022, 6, 14, 3, 40);
final DateTime maximum = DateTime(2022, 6, 14, 3, 49);
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: SizedBox(
height: 400.0,
width: 400.0,
child: CupertinoDatePicker(
initialDateTime: initial,
minimumDate: minimum,
maximumDate: maximum,
minuteInterval: 5,
use24hFormat: true,
onDateTimeChanged: (DateTime newDate) {
date = newDate;
},
),
),
),
),
);
// Drag picker minutes to min date
await tester.drag(find.text('40'), const Offset(0.0, 32.0), touchSlopY: 0.0, warnIfMissed: false);
await tester.pumpAndSettle();
// Returns to min date.
expect(
date,
DateTime(2022, 6, 14, 3, 35),
);
// Drag picker minutes to max date
await tester.drag(find.text('50'), const Offset(0.0, -64.0), touchSlopY: 0.0, warnIfMissed: false);
await tester.pumpAndSettle();
// Returns to max date.
expect(
date,
DateTime(2022, 6, 14, 3, 45),
);
});
} }
Widget _buildPicker({ Widget _buildPicker({
......
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