Skip to content

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

@h1542462994

Description

@h1542462994

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions