Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Update TextEditingController.text with other TextFields TextEditingController.text values + extra String

I have a name & last name TextFormField in my App

ScreenShot 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  TextEditingController emailTextController = TextEditingController();
  TextEditingController nameTextController = TextEditingController();
  TextEditingController lastNameTextController = TextEditingController();
  • if I init emailTextController to be equal to nameTextController it 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

Second ScreenShot

>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,
)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading