PhoneInput constructor
PhoneInput({
- Key? key,
- bool enabled = true,
- AutovalidateMode? autovalidateMode,
- String? initialValue,
- FormFieldSetter<
String> ? onSaved, - FormFieldValidator<
String> ? validator, - required TextEditingController controller,
- BoxConstraints? constraints,
- String labelText = "Phone",
- bool readOnly = false,
- dynamic onChanged()?,
- List<
TextInputFormatter> ? inputFormatters, - Widget? prefix,
- Widget? prefixIcon,
- Widget? suffix,
- 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,
),
);
});