Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 DatePicker: when you set endDate, popup will not show year same as endDate.year. #874

Closed
h1542462994 opened this issue Jul 5, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@h1542462994
Copy link

Describe the bug
For example, now is 2023/7/5, and you set endDate 2023/7/5 to DataPicker, will not show 2023 in year scroll items.

To Reproduce
Steps to reproduce the behavior:

  1. Add a DataPicker Widget.
  2. Set endDate to 2023/7/5.
  3. click the DataPicker and show, the first item is 1923, the last item is 2022.

Expected behavior
2023 show be current selected, because it should select the date (default now) 2023/7/5

Screenshots
image

Additional context
current version is: ^4.4.0
lock version is: 4.5.1
but now version also has this bug.

It is the tips about how to solve this bug.

class _DatePickerState ::property currentYear

int get currentYear {
  return List.generate(endYear - startYear, (index) {
    return startYear + index;
  }).firstWhere((v) => v == date.year, orElse: () => 0);
}

it should be, take 2023 ~ 2024 for example, it has 2 items.

int get currentYear {
  return List.generate(endYear - startYear + 1, (index) {
    return startYear + index;
  }).firstWhere((v) => v == date.year, orElse: () => 0);
}
@h1542462994
Copy link
Author

  1. now has anothor position should be fixed at: _DatePickerContentPopUp::build::yearWidget
final yearWidget = [
  Expanded(
    child: () {
      final years = widget.endDate.year - widget.startDate.year;
      final formatter = DateFormat.y(locale.toString());
      // YEAR

it should be

final yearWidget = [
  Expanded(
    child: () {
      final years = widget.endDate.year - widget.startDate.year + 1;
      final formatter = DateFormat.y(locale.toString());
      // YEAR
  1. the date in onChanged Callback will be automatically truncate to the startTime of selectedDate.

for example: if you choose 2023/7/5, it should be 2023/7/5 0:00:00 without any other time infos.

@bdlukaa bdlukaa added the bug Something isn't working label Jul 6, 2023
@bdlukaa bdlukaa closed this as completed in d152dc9 Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants