I have a name & last name TextFormField in my App
I’d like the disabled e-mail field to auto-complete with the value written inside name field and last name field + the company domain : @company.com
TextEditingController emailTextController = TextEditingController();
TextEditingController nameTextController = TextEditingController();
TextEditingController lastNameTextController = TextEditingController();
- if I init
emailTextControllerto be equal tonameTextControllerit works, both value change
@override
onInit() async {
emailTextController = emailNameTextController;
super.onInit();
}
but what I’d like would be for emailTextController.text to have also @company.com at the end
@override
onInit() async {
emailTextController.text = emailNameTextController.text + '@company.com';
super.onInit();
}
but value of email field doesn’t update with value from nameField
>Solution :
You can use onSubmited or onChanged on the lastName textfield
TextField(
controller: lastNameTextController ,
onSubmitted: (text) {
emailTextController.text = nameTextController.text + lastNameTextController.text + '@company.com';
},
//OR us this
onChanged(){
emailTextController.text = nameTextController.text + lastNameTextController.text + '@company.com';
},
textInputAction: TextInputAction.send,
)

