mirror of
https://github.com/Iconica-Development/flutter_input_library.git
synced 2025-05-18 17:03:45 +02:00
fix: Made year an optional parameter for generating month list
This commit is contained in:
parent
9a81543e8c
commit
e3da63c7c6
2 changed files with 5 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue