ValidatorField constructor

ValidatorField({
  1. required AbstractValidator<String> abstractValidator,
  2. required String validatorMessage,
  3. String? labelPrefix,
  4. String? label,
  5. Widget? labelWidget,
  6. TextEditingController? controller,
  7. String? validator(
    1. String? value
    )?,
  8. bool obscureText = false,
  9. List<TextInputFormatter>? inputFormatter,
  10. TextAlign textAlign = TextAlign.start,
  11. int? maxLength,
  12. void onSaved(
    1. String?
    )?,
  13. String? initialValue,
  14. bool enabled = true,
  15. AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
  16. ValueChanged<String?>? onChanged,
  17. FocusNode? focusNode,
  18. TextInputAction? textInputAction,
  19. ValueChanged<String?>? onFieldSubmitted,
  20. bool autocorrect = false,
  21. bool enableSuggestions = false,
  22. TextCapitalization textCapitalization = TextCapitalization.none,
  23. EdgeInsets scrollPadding = const EdgeInsets.all(20),
  24. bool enableInteractiveSelection = true,
  25. bool filled = false,
  26. Color? fillColor,
  27. bool required = true,
  28. Iterable<String>? autofillHints,
  29. bool readOnly = false,
  30. TextStyle? style,
  31. InputDecoration? decoration,
  32. EdgeInsets padding = const EdgeInsets.all(8),
  33. String? hintText,
  34. EdgeInsets? contentPadding,
  35. String? counterText = '',
  36. Widget? prefix,
  37. Widget? prefixIcon,
  38. Widget? suffix,
  39. Widget? suffixIcon,
  40. bool trimOnSaved = false,
  41. void onTap()?,
  42. int? sizeExtraSmall,
  43. int? sizeSmall,
  44. int? sizeMedium,
  45. int? sizeLarge,
  46. int? sizeExtraLarge,
  47. double? minHeight,
  48. Key? key,
})

Implementation

ValidatorField({
  required AbstractValidator<String> abstractValidator,
  required String validatorMessage,
  super.labelPrefix,
  super.label,
  super.labelWidget,
  super.controller,
  String? Function(String? value)? validator,
  super.obscureText,
  List<TextInputFormatter>? inputFormatter,
  super.textAlign,
  super.maxLength,
  void Function(String?)? onSaved,
  String? initialValue,
  super.enabled,
  super.autoValidateMode,
  super.onChanged,
  super.focusNode,
  super.textInputAction,
  super.onFieldSubmitted,
  super.autocorrect = false,
  super.enableSuggestions = false,
  super.textCapitalization,
  super.scrollPadding,
  super.enableInteractiveSelection,
  super.filled,
  super.fillColor,
  bool required = true,
  super.autofillHints,
  super.readOnly,
  super.style,
  super.decoration,
  super.padding,
  super.hintText,
  super.contentPadding,
  super.counterText,
  super.prefix,
  super.prefixIcon,
  super.suffix,
  super.suffixIcon,
  super.trimOnSaved = false,
  super.onTap,
  super.sizeExtraSmall,
  super.sizeSmall,
  super.sizeMedium,
  super.sizeLarge,
  super.sizeExtraLarge,
  super.minHeight,
  super.key,
})  : assert(
        initialValue == null || controller == null,
        'initialValue or controller must be null.',
      ),
      assert(
        label == null || labelWidget == null,
        'label or labelWidget must be null.',
      ),
      super(
        keyboard: abstractValidator.keyboard,
        validator: enabled
            ? (String? value) {
                if (!required && (value == null || value.isEmpty)) {
                  return null;
                }

                if (value == null || !abstractValidator.isValid(value)) {
                  return validatorMessage;
                }

                if (validator != null) {
                  return validator(value);
                }

                return null;
              }
            : null,
        minLines: 1,
        maxLines: 1,
        inputFormatter: <TextInputFormatter>[
          ...abstractValidator.inputFormatters ?? <TextInputFormatter>[],
          ...inputFormatter ?? <TextInputFormatter>[],
        ],
        onSaved: enabled
            ? (String? value) {
                if (value != null) {
                  value = abstractValidator.strip(value);
                }

                if (!required && value != null && value.isEmpty) {
                  value = null;
                }

                onSaved?.call(value);
              }
            : null,
        initialValue: initialValue != null
            ? abstractValidator.format(initialValue)
            : null,
      );