validate static method

String? validate(
  1. String? value, {
  2. bool required = false,
  3. double max = 100,
})

Implementation

static String? validate(
  String? value, {
  bool required = false,
  double max = 100,
}) {
  if (value == null || value.trim().isEmpty) {
    return required ? ConectarDesignSystem.labels.requiredField : null;
  }

  final tax = double.tryParse(value.trim().replaceAll(',', '.'));

  if (tax == null || tax.isNaN || tax < 0 || tax > max) {
    return ConectarDesignSystem.labels.taxOutOfRange
        .replaceAll('{max}', _formatMax(max));
  }

  return null;
}