CreditCardCodeField constructor

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

Implementation

CreditCardCodeField({
  required CreditCardType creditCardType,
  String validatorMessage = 'Informe o %s.',
  super.labelPrefix,
  String? label,
  super.controller,
  String? Function(String? value)? validator,
  super.textAlign,
  void Function(String? value)? 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.style,
  super.decoration,
  super.padding,
  super.contentPadding,
  super.counterText,
  super.prefix,
  super.prefixIcon,
  super.suffix,
  super.suffixIcon,
  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.',
      ),
      super(
        keyboard: TextInputType.number,
        label: label ?? creditCardType.code.name,
        validator: enabled
            ? (String? value) {
                if (!required && (value == null || value.isEmpty)) {
                  return null;
                }

                if (value == null || !creditCardType.cvvCheck(value)) {
                  return sprintf(
                    validatorMessage,
                    <dynamic>[label ?? creditCardType.code.name],
                  );
                }

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

                return null;
              }
            : null,
        minLines: 1,
        maxLines: 1,
        maxLength: creditCardType.code.size.fold<int>(0, max),
        hintText: List<String>.generate(
          creditCardType.code.size.fold<int>(0, max),
          (_) => 'X',
        ).join(),
        obscureText: false,
        inputFormatter: <TextInputFormatter>[
          FilteringTextInputFormatter.digitsOnly,
        ],
        onSaved: enabled
            ? (String? value) {
                if (onSaved != null) {
                  if (!required && value != null && value.isEmpty) {
                    value = null;
                  }

                  onSaved(value);
                }
              }
            : null,
      );