Repository navigation
Cupertino date picker does not work correctly when using minuteInterval and scrolling past the endDate #97010
Copy link
Copy link
Closed
Labels
f: date/time pickerDate or time picker widgetsDate or time picker widgetsfound in release: 2.8Found to occur in 2.8Found to occur in 2.8found in release: 2.9Found to occur in 2.9Found to occur in 2.9frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagescupertino_ui package in flutter/packagesplatform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Steps to Reproduce
The Cupertino date picker does not work correctly when using minuteInterval and scrolling past the endDate
What happens: In the attached example, when scrolling past the end time of 40 minutes, it scrolls back to minute 20.
Expected: If endDate is at minute 40 and I scroll to minute 45, it should scroll back to 40.
The reason is that the scroll controller does not take the minuteInterval into account when scrolling back.
I have opened a PR here.
Code sample
class _MyHomePageState extends State<MyHomePage> {
DateTime? selectedDate;
DateTime now = DateTime.now();
late DateTime startDate = DateTime(now.year, now.month, now.day, 0, 5, 0);
late DateTime endDate = DateTime(now.year, now.month, now.day, 19, 40, 0);
int minuteInterval = 5;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter Cupertino DatePicker"),
),
body: Container(
margin: EdgeInsets.all(40),
width: double.infinity,
height: MediaQuery.of(context).size.height * 0.25,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
child: Text("Show DatePicker"),
onPressed: () {
showDatePicker();
},
),
Text(selectedDate == null ? "" : "$selectedDate")
],
),
),
);
}
void showDatePicker() {
showCupertinoModalPopup(
context: context,
builder: (BuildContext builder) {
return Container(
height: MediaQuery.of(context).copyWith().size.height * 0.30,
color: Colors.white,
child: CupertinoDatePicker(
initialDateTime: _adjustDateTime(DateTime.now()),
onDateTimeChanged: (newDate) {},
use24hFormat: false,
minuteInterval: minuteInterval,
minimumDate: _adjustDateTime(startDate),
maximumDate: _adjustDateTime(endDate),
mode: CupertinoDatePickerMode.dateAndTime,
),
);
},
);
}
DateTime? _adjustDateTime(DateTime? date) {
return date == null
? null
: DateTime(date.year, date.month, date.day, date.hour,
date.minute - (date.minute % minuteInterval), 0, 0, 0);
}
Logs
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, 2.9.0-1.0.pre.433, on macOS 11.5.2 20G95 darwin-arm, locale en-ES)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.63.2)
[✓] VS Code (version 1.64.0-insider)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
f: date/time pickerDate or time picker widgetsDate or time picker widgetsfound in release: 2.8Found to occur in 2.8Found to occur in 2.8found in release: 2.9Found to occur in 2.9Found to occur in 2.9frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagescupertino_ui package in flutter/packagesplatform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Activity
darshankawar commentedon Jan 24, 2022
@ansolantz
Thanks for the report and potential fix, but I ran your code sample using latest master but was unable to replicate the behavior. Are there are specific steps to replicate ?
97010.mov
Flutter (Channel master, 2.9.0-1.0.pre.463)ansolantz commentedon Jan 24, 2022
Hi @darshankawar,
Thanks for your reply! I'm sorry, I did not describe it clear enough. The issue occurs when you scroll past the
maximumDate, in my example I put today at 19:40 (7:40 PM) asendDate. Then, instead of scrolling back to 40 minutes, it scrolls back to minute 20. You also need to set theminuteIntervallarger than 1 (in my case I use 5).cupertino-date-picker-issue.mov
darshankawar commentedon Jan 25, 2022
Thanks for the update. Using above explaination, I do see the same behavior, ie, the
minuteIntervaldoesn't reset to most recent value but defaults to 20 once it goes past theendDate:97010.mov
master, stable flutter doctor -v
complete code sample
NikosTsesmelis commentedon Mar 3, 2022
Is there any progress with this? We cannot use minimumDate and maximumDate with minuteInterval and we need this to upload.
NikosTsesmelis commentedon May 30, 2022
This is not fixed yet in flutter 3.1.
darshankawar commentedon May 30, 2022
@NikosTsesmelis
The issue is still open and not assigned yet. There's a PR opened by OP but seem to need tests to progress further.
Hixie commentedon May 31, 2022
PR #97012 was written to fix this bug but unfortunately it was not completed (it just needed tests) so the PR has been closed. If anyone would like to start from that PR and apply the review comments and drive this PR to completion, you are definitely welcome to do so!
NikosTsesmelis commentedon Jun 21, 2022
I have opened this pr for over a week now and there is no answer. Have I missed something because I have not done this again?
Hixie commentedon Jun 24, 2022
@NikosTsesmelis Our bad, sorry about that. Let me see if I can find out why it wasn't noticed during triage.
Hixie commentedon Jul 11, 2022
Sorry for the continued delay.
TahaTesser commentedon Jul 21, 2022
#105958 landed
github-actions commentedon Aug 4, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.