isBetween method

ContractValidations isBetween(
  1. dynamic value,
  2. dynamic from,
  3. dynamic into,
  4. String property,
  5. String message,
)

Notifica se value NÃO estiver entre from e into (inclusivo).

Implementation

ContractValidations isBetween(dynamic value, dynamic from, dynamic into,
    String property, String message) {
  final hasDatetime =
      (value is DateTime) || (from is DateTime) || (into is DateTime);

  if (hasDatetime) {
    final dt = value as DateTime;
    final isInRange =
        (dt.isAfter(from as DateTime) || dt.isAtSameMomentAs(from)) &&
            (dt.isBefore(into as DateTime) || dt.isAtSameMomentAs(into));
    if (!isInRange) {
      addNotifications(
          ValidationNotification(property: property, message: message));
    }
    return this;
  }

  if (value < from || value > into) {
    addNotifications(
        ValidationNotification(property: property, message: message));
  }

  return this;
}