isUnder13 method

  1. @useResult
bool isUnder13({
  1. DateTime? today,
})

Returns true if the date (of birth) is under 13 years old.

This is useful for determining non-child content access based on the Children's Online Privacy Protection Act (COPPA).

today can be optionally provided to specify the date to compare against. If not provided, the current date is used.

Implementation

@useResult
bool isUnder13({DateTime? today}) {
  final DateTime resolvedToday = today ?? DateTime.now();

  if (isAfter(resolvedToday)) {
    return false;
  }

  final DateTime thirteenthBirthday = addYears(DateConstants.coppaMinAge);

  return resolvedToday.isBefore(thirteenthBirthday);
}