addMonthsToMonthDate method Null safety

DateTime addMonthsToMonthDate(
  1. DateTime monthDate,
  2. int monthsToAdd
)

Returns a DateTime that is monthDate with the added number of months and the day set to 1 and time set to midnight.

For example:

DateTime date = DateTime(year: 2019, month: 1, day: 15);
DateTime futureDate = DateUtils.addMonthsToMonthDate(date, 3);

date would be January 15, 2019. futureDate would be April 1, 2019 since it adds 3 months.

Implementation

static  DateTime addMonthsToMonthDate(DateTime monthDate, int monthsToAdd) {
  return DateTime(monthDate.year, monthDate.month + monthsToAdd);
}