fix: Made year an optional parameter for generating month list

This commit is contained in:
Jacques 2023-11-01 16:08:21 +01:00
parent 9a81543e8c
commit e3da63c7c6
2 changed files with 5 additions and 3 deletions

View file

@ -37,7 +37,8 @@ class _MyHomePageState extends State<MyHomePage> {
var formKey = GlobalKey<FormState>();
var weekDays = TypeUtils().createWeekDays(WeekDay.monday, WeekDay.sunday);
var dates = TypeUtils().createMonthList(Month.january, Month.december, 2023);
var dates =
TypeUtils().createMonthList(Month.january, Month.december, year: 2023);
var years = TypeUtils().createYearList(2000, 2023);
@override

View file

@ -46,14 +46,15 @@ class TypeUtils {
}
/// Creates list of Datetime with the months from start to end.
List<DateTime> createMonthList(Month start, Month end, int year) {
List<DateTime> createMonthList(Month start, Month end, {int? year}) {
if (start.index > end.index) {
throw ArgumentError('Start month must be before or equal to end month.');
}
List<DateTime> result = [];
for (int i = start.index; i <= end.index; i++) {
result.add(DateTime(year, Month.values[i].index + 1, 1));
result.add(
DateTime(year ?? DateTime.now().year, Month.values[i].index + 1, 1));
}
return result;