PhoneInput constructor

PhoneInput({
  1. Key? key,
  2. bool enabled = true,
  3. AutovalidateMode? autovalidateMode,
  4. String? initialValue,
  5. FormFieldSetter<String>? onSaved,
  6. FormFieldValidator<String>? validator,
  7. required TextEditingController controller,
  8. BoxConstraints? constraints,
  9. String labelText = "Phone",
  10. bool readOnly = false,
  11. dynamic onChanged(
    1. String
    )?,
  12. List<TextInputFormatter>? inputFormatters,
  13. Widget? prefix,
  14. Widget? prefixIcon,
  15. Widget? suffix,
  16. Widget? suffixIcon,
})

Implementation

PhoneInput({
  super.key,
  super.enabled,
  super.autovalidateMode,
  super.initialValue,
  super.onSaved,
  super.validator,
  required this.controller,
  this.constraints,
  this.labelText = "Phone",
  this.readOnly = false,
  this.onChanged,
  this.inputFormatters,
  this.prefix,
  this.prefixIcon,
  this.suffix,
  this.suffixIcon,
}) : super(builder: (field) {
        return TextFormField(
          controller: controller,
          initialValue: initialValue,
          autovalidateMode: autovalidateMode,
          onSaved: onSaved,
          readOnly: readOnly,
          inputFormatters: inputFormatters,
          validator: validator ?? (value) => Validators.validatePhone(value),
          onChanged: onChanged ??
              (value) {
                if (value.length == 3) {
                  controller.value = TextEditingValue(
                      text: '($value) ', selection: const TextSelection.collapsed(offset: 6));
                } else if (value.length == 9) {
                  controller.value = TextEditingValue(
                      text: '$value-', selection: const TextSelection.collapsed(offset: 10));
                }
              },
          decoration: InputDecoration(
            labelText: labelText,
            constraints: constraints,
            border: const OutlineInputBorder(),
            enabled: enabled,
            prefix: prefix,
            prefixIcon: prefixIcon,
            suffix: suffix,
            suffixIcon: suffixIcon,
          ),
        );
      });