getValidDate function

dynamic getValidDate(
  1. dynamic minDate,
  2. dynamic maxDate,
  3. dynamic date
)

Return the given date if the date in between first and last date else return first date/last date when the date before of first date or after last date

Implementation

dynamic getValidDate(dynamic minDate, dynamic maxDate, dynamic date) {
  if (date.isAfter(minDate) == true) {
    if (date.isBefore(maxDate) == true) {
      return date;
    } else {
      return maxDate;
    }
  } else {
    return minDate;
  }
}