When pre-populating an initial value field in a TextFormField it does not update with reactive data. To solve this create a Key and use the value you want to display with.toString()

TextFormField(
  key: Key(answerData.selectedAnswer.comment.toString()), // <- Magic!
  initialValue: answerData.selectedAnswer.comment,
  maxLines: 8,
  style: TextStyle(
    color: Colors.black,
  ),
  cursorColor: Colors.black,
  keyboardType: TextInputType.text,
  decoration: InputDecoration(
  labelText: 'Enter any comments here.',
  labelStyle: TextStyle(
    color: Colors.black,
  ),
  focusColor: Colors.black,
  ),
  validator: (value) {
    setState(() {
      answerData.setComment(value);
    });
    return;
   },
 )

Last modified: 02/11/2020

Comments

Write a Reply or Comment

Your email address will not be published.