CepField constructor

CepField({
  1. bool trim = false,
  2. bool strip = true,
  3. String? malformed,
  4. String? blank,
  5. TextEditingController? controller,
  6. String? initialValue,
  7. InputDecoration? decoration = const InputDecoration(),
  8. TextInputAction? textInputAction,
  9. TextStyle? style,
  10. TextDirection? textDirection,
  11. TextAlign textAlign = TextAlign.start,
  12. bool readOnly = false,
  13. String obscuringCharacter = '•',
  14. bool obscureText = false,
  15. bool autocorrect = true,
  16. int? maxLength,
  17. ValueChanged<String>? onChanged,
  18. VoidCallback? onEditingComplete,
  19. ValueChanged<String>? onFieldSubmitted,
  20. FormFieldSetter<String>? onSaved,
  21. FormFieldValidator<String>? validator,
  22. bool? enabled,
  23. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  24. bool enableInteractiveSelection = true,
  25. AutovalidateMode? autovalidateMode,
  26. Key? key,
})

Cep Form Field.

trim whether or not to trim the input data. strip sets whether or not the hyphen '-' of the input value will be removed from it. If set to true, which is the default value, the input value of the onSaved, onChanged and onFieldSubmitted callbacks will always be an unmasked (simple) value. malformed the error message in case of a malformed CEP. blank the error message in case of blank field; if omitted, the field will not be required. validator an optional extra validation step.

Implementation

CepField({
  bool trim = false,
  bool strip = true,
  String? malformed,
  String? blank,
  TextEditingController? controller,
  String? initialValue,
  InputDecoration? decoration = const InputDecoration(),
  TextInputAction? textInputAction,
  TextStyle? style,
  TextDirection? textDirection,
  TextAlign textAlign = TextAlign.start,
  bool readOnly = false,
  String obscuringCharacter = '•',
  bool obscureText = false,
  bool autocorrect = true,
  int? maxLength,
  ValueChanged<String>? onChanged,
  VoidCallback? onEditingComplete,
  ValueChanged<String>? onFieldSubmitted,
  FormFieldSetter<String>? onSaved,
  FormFieldValidator<String>? validator,
  bool? enabled,
  EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  bool enableInteractiveSelection = true,
  AutovalidateMode? autovalidateMode,
  Key? key,
})  : _toCepField = ((context) {
        final FormFieldSetter<String>? onSavedStrip = onSaved == null
            ? null
            : !strip
                ? onSaved
                : (String? mask) => onSaved(CepStrip(mask ?? '').value);
        final ValueChanged<String>? onChangedStrip = onChanged == null
            ? null
            : !strip
                ? onChanged
                : (String mask) => onChanged(mask.replaceAll('-', ''));

        final ValueChanged<String>? onFieldSubmittedStrip =
            onFieldSubmitted == null
                ? null
                : !strip
                    ? onFieldSubmitted
                    : (String mask) =>
                        onFieldSubmitted(mask.replaceAll('-', ''));
        return BasicTextField(
          validator: Pair.str(Cep(mal: malformed), validator ?? _dummy),
          blank: blank,
          trim: trim,
          keyboardType: TextInputType.number,
          controller: controller,
          initialValue: initialValue,
          decoration: decoration,
          textInputAction: textInputAction,
          style: style,
          textDirection: textDirection,
          textAlign: textAlign,
          readOnly: readOnly,
          obscuringCharacter: obscuringCharacter,
          obscureText: obscureText,
          autocorrect: autocorrect,
          maxLength: maxLength,
          onChanged: onChangedStrip,
          onEditingComplete: onEditingComplete,
          onFieldSubmitted: onFieldSubmittedStrip,
          onSaved: onSavedStrip,
          inputFormatters: [
            MaskTextInputFormatter(
              mask: '#####-###',
              filter: {"#": RegExp(r'\d')},
            )
          ],
          enabled: enabled,
          scrollPadding: scrollPadding,
          enableInteractiveSelection: enableInteractiveSelection,
          autovalidateMode: autovalidateMode,
        );
      }),
      super(key: key);