BrPhoneField constructor

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

Brazilian Phone Numbers Form Field.

trim whether or not to trim the input data. strip sets whether or not the phone number value will be stripped of its parenthesis '(' and ')', hyphen '-' and space ' ' characters. If set to true, which is the default value, the input parameter of the onSaved, onChanged, and onFieldSubmitted functions will contain only digits. malformed the error message in case of a malformed phone number. blank the error message in case of blank field; if omitted, the field will not be required. validator an optional extra validation step.

Implementation

BrPhoneField({
  bool trim = false,
  bool strip = true,
  String? malformed,
  String? blank,
  FormFieldValidator<String>? validator,
  String? initialValue,
  TextEditingController? controller,
  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,
  bool? enabled,
  EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  bool enableInteractiveSelection = true,
  AutovalidateMode? autovalidateMode,
  Key? key,
})  : _toBrPhoneField = ((context) {
        final FormFieldSetter<String>? onSavedStrip = onSaved == null
            ? null
            : !strip
                ? onSaved
                : (String? mask) => onSaved(BrPhoneStrip(mask ?? '').value);
        final ValueChanged<String>? onChangedStrip = onChanged == null
            ? null
            : !strip
                ? onChanged
                : (String mask) =>
                    onChanged(mask.replaceAll(RegExp(r'[-()\s]'), ''));

        final ValueChanged<String>? onFieldSubmittedStrip =
            onFieldSubmitted == null
                ? null
                : !strip
                    ? onFieldSubmitted
                    : (String mask) => onFieldSubmitted(
                          mask.replaceAll(RegExp(r'[-()\s]'), ''),
                        );
        return BasicTextField(
          validator: Pair.str(BrPhone(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);