instanceValidateConstraints method

  1. @override
void instanceValidateConstraints(
  1. ValidateContext context,
  2. int value
)
override

Validates that the argument matches constraints (minimum length, etc.).

Example

import 'package:kind/kind.dart';

void main() {
  final kind = const StringKind();

  final context = ValidateContext();
  context.instanceValidate('abc', kind: kind);
  // The above calls kind.instanceValidateConstraints(...)
}

Implementation

@override
void instanceValidateConstraints(ValidateContext context, int value) {
  if (value < 0 && !safeInJs) {
    final min = this.min;
    final max = this.max;
    if ((min == null || min < 0) && (max != null && max <= maxSafeInJs)) {
      context.invalid(
        value: value,
        message: 'Not an unsigned 64-bit integer.',
      );
      super.instanceValidateConstraints(context, value);
      return;
    }
  }
  if (safeInJs && !(value >= 0 && value <= maxSafeInJs)) {
    context.invalid(
      value: value,
      message: 'Value is outside the safe range in Javascript (52 bits)',
    );
  }
  super.instanceValidateConstraints(context, value);
}