From dc1eefa997a354339cb6e2823140e5fee89b3014 Mon Sep 17 00:00:00 2001 From: Alexander Ryzhov Date: Thu, 7 Feb 2019 13:20:10 -0800 Subject: [PATCH] Fixed #27621: CupertinoTimerPicker breaks if minuteInterval > 1 (#27647) --- .../lib/src/cupertino/date_picker.dart | 4 +-- .../test/cupertino/date_picker_test.dart | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart index cb43389a3c..802d40cfaf 100644 --- a/packages/flutter/lib/src/cupertino/date_picker.dart +++ b/packages/flutter/lib/src/cupertino/date_picker.dart @@ -1150,7 +1150,7 @@ class _CupertinoTimerPickerState extends State { backgroundColor: _kBackgroundColor, onSelectedItemChanged: (int index) { setState(() { - selectedMinute = index; + selectedMinute = index * widget.minuteInterval; widget.onTimerDurationChanged( Duration( hours: selectedHour ?? 0, @@ -1262,7 +1262,7 @@ class _CupertinoTimerPickerState extends State { backgroundColor: _kBackgroundColor, onSelectedItemChanged: (int index) { setState(() { - selectedSecond = index; + selectedSecond = index * widget.secondInterval; widget.onTimerDurationChanged( Duration( hours: selectedHour ?? 0, diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart index ae9f024dec..3e8f452095 100644 --- a/packages/flutter/test/cupertino/date_picker_test.dart +++ b/packages/flutter/test/cupertino/date_picker_test.dart @@ -198,6 +198,39 @@ void main() { ); }); }); + + testWidgets('picker honors minuteInterval and secondInterval', (WidgetTester tester) async { + Duration duration; + await tester.pumpWidget( + CupertinoApp( + home: SizedBox( + height: 400.0, + width: 400.0, + child: CupertinoTimerPicker( + minuteInterval: 10, + secondInterval: 15, + initialTimerDuration: const Duration(hours: 10, minutes: 40, seconds: 45), + mode: CupertinoTimerPickerMode.hms, + onTimerDurationChanged: (Duration d) { + duration = d; + }, + ), + ), + ), + ); + + await tester.drag(find.text('40'), _kRowOffset); + await tester.pump(); + await tester.drag(find.text('45'), -_kRowOffset); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + expect( + duration, + const Duration(hours: 10, minutes: 50, seconds: 30), + ); + }); + group('Date picker', () { testWidgets('mode is not null', (WidgetTester tester) async { expect(