parse method

  1. @override
double parse(
  1. dynamic value, {
  2. String path = '',
})
override

Implementation

@override
double parse(dynamic value, {String path = ''}) {
  clearErrors();

  if (value == null) {
    addError(ZardIssue(
      message: message ?? 'Value is required and cannot be null',
      type: 'required_error',
      value: value,
      path: path.isEmpty ? null : path,
    ));
    throw ZardError(issues);
  }

  double? coercedValue;
  try {
    coercedValue = double.tryParse(value.toString());
  } catch (_) {}

  if (coercedValue == null) {
    addError(ZardIssue(
      message: message ?? 'Failed to coerce value to double',
      type: 'coerce_error',
      value: value,
      path: path.isEmpty ? null : path,
    ));
    throw ZardError(issues);
  }

  return super.parse(coercedValue, path: path);
}