Home > OS >  Update TextEditingController.text with other TextFields TextEditingController.text values extra St
Update TextEditingController.text with other TextFields TextEditingController.text values extra St

Time:02-04

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

  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

CodePudding user response:

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

  •  Tags:  
  • Related