【发布时间】:2022-10-04 19:05:45
【问题描述】:
正如标题所示,我正在使用 DateRangePicker 将日期范围添加到数组中。如果可能的话,我希望能够将数组中已经选择的日期“变灰”。有没有办法做到这一点?
【问题讨论】:
正如标题所示,我正在使用 DateRangePicker 将日期范围添加到数组中。如果可能的话,我希望能够将数组中已经选择的日期“变灰”。有没有办法做到这一点?
【问题讨论】:
【讨论】:
这是返回范围之间的日期以防其他人需要的解决方案。
List<DateTime> getDaysInBetweenIncludingStartEndDate(
{required DateTime startDateTime, required DateTime endDateTime}) {
// Converting dates provided to UTC
// So that all things like DST don't affect subtraction and addition on dates
DateTime startDateInUTC =
DateTime.utc(startDateTime.year, startDateTime.month, startDateTime.day);
DateTime endDateInUTC =
DateTime.utc(endDateTime.year, endDateTime.month, endDateTime.day);
// Created a list to hold all dates
List<DateTime> daysInFormat = [];
// Starting a loop with the initial value as the Start Date
// With an increment of 1 day on each loop
// With condition current value of loop is smaller than or same as end date
for (DateTime i = startDateInUTC;
i.isBefore(endDateInUTC) || i.isAtSameMomentAs(endDateInUTC);
i = i.add(const Duration(days: 1))) {
// Converting back UTC date to Local date if it was local before
// Or keeping in UTC format if it was UTC
if (startDateTime.isUtc) {
daysInFormat.add(i);
} else {
daysInFormat.add(DateTime(i.year, i.month, i.day));
}
}
return daysInFormat;
}
【讨论】: