'how to set initialvalue in textformfield

i'm trying to supply an initial value however i keep getting errors. how do i approach this. stuff is a list of values by the way so it holds a list<map<string, dynamic>> function

Widget _buildDescriptionTextField(){
    return Padding(
      padding: const EdgeInsets.only(right: 30),
      child: TextFormField(
        decoration: InputDecoration(labelText:  'Description',),

         initialValue: widget.stuff['description'],

        maxLines: 4,
        validator: (String? value){
          //if (value!.length <= 0){      // use one or the other
          if (value!.isEmpty || value.length < 10 ){                  //   (||) means or
            return 'Description is required and should be 10+ characters';
          }
        },
        onSaved: (String? value){
          setState(() {
            formData['description'] = value!;
          // descriptionValue = value!;
          });
        },),
    );
  }


Solution 1:[1]

Here is the example for initial text in text field

class _FooState extends State<Foo> {
  TextEditingController _controller;

  @override
  void initState() {
    super.initState();
    _controller = new TextEditingController(text: 'Initial value');
  }

  @override
  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[
        new TextField(
          // The TextField is first built, the controller has some initial text,
          // which the TextField shows. As the user edits, the text property of
          // the controller is updated.
          controller: _controller,
        ),
        new RaisedButton(
          onPressed: () {
            // You can also use the controller to manipuate what is shown in the
            // text field. For example, the clear() method removes all the text
            // from the text field.
            _controller.clear();
          },
          child: new Text('CLEAR'),
        ),
      ],
    );
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 G H Prakash