TextFormField Value to TextField New Line

Issue

I have a question. I want to send the return(returnvalue1…2…3) output from TextFormField to a TextField. I want it to append each output to newline without clearing the TextField.
How can I do that?
Thank you for your help.

TextFormField Codes:

TextFormField(
              decoration: InputDecoration(
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.green,
                      width: 2.0,
                    ),
                  ),
                  prefixText: 'test: ',
                  prefixStyle: TextStyle(color: Colors.green, fontSize: 20),
                  errorStyle: TextStyle(
                      backgroundColor: Colors.black,
                      color: Colors.green,
                      fontSize: 18)
                  ),

              style: TextStyle(
                  fontSize: 18,
                  color: Colors.green,
                  backgroundColor: Colors.black),
              validator: (value) {
                if (value == null || value.isEmpty) {
                  return AppLocalizations.of(context)!.returnvalue1;
                }
                if (value == girdi) {
                  return AppLocalizations.of(context)!.returnvalue2;
                } else {
                  return AppLocalizations.of(context)!.returnvalue3;
                }
              },
            ),
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 16.0),
              child: ElevatedButton(
                onPressed: () {
                  if (_formKey.currentState!.validate()) {
                  }
                },
                child: Text(AppLocalizations.of(context)!.addTextToNewLine),
              ),
            ),

TextField Codes:

 TextField(
      readOnly: true,
      showCursor: false,
      style: TextStyle(
          fontSize: 18,
          color: Colors.green,
          backgroundColor: Colors.black),
    ),

Solution

Add controllers to both TextFormField and TextField. Then, do this when you want to append each output:

textFieldController.text = textFieldController.text + textFormFieldController.text + "\n";

Answered By – Zan

Answer Checked By – David Goodson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *