firstDayNextMonth static method
Returns the first day of the month following the given month and year,
or null if month is invalid.
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
static DateTime? firstDayNextMonth({required int month, required int year}) {
// ref: https://stackoverflow.com/questions/61881850/sort-list-based-on-boolean
// ref: https://stackoverflow.com/questions/67144785/flutter-dart-datetime-max-min-value
if (month < DateConstants.minMonth || month > DateConstants.maxMonth) {
// invalid
return null;
}
// there are ALWAYS 28 days in any month
// ignore: saropa_lints/avoid_datetime_constructor -- month is range-checked 1..12 by the guard above and minDaysInAnyMonth (28) exists in every month
final DateTime someDayNextMonth = DateTime(
year,
month,
DateConstants.minDaysInAnyMonth,
).addDays(DateConstants.daysToAddToGetNextMonth);
// Omitted day and time default to the 1st at local midnight; December has
// already advanced to January of the next year via addDays above.
// ignore: saropa_lints/avoid_datetime_constructor, saropa_lints/avoid_datetime_constructor_unvalidated -- year/month from a valid DateTime; the omitted day defaults to 1, which exists in every month
return DateTime(someDayNextMonth.year, someDayNextMonth.month);
}