Panchal Ravi
Panchal Ravi

Reputation: 33

How to Update Particular TextFormFiled value Using TextEditing Controller after fetching data from API in flutter?

** TextEditingController gstController = TextEditingController( text: snapshot.data![index].gSTNo.toString());

TextFormField( controller: gstController, decoration: InputDecoration( hintText: 'Enter GST No', border: InputBorder.none, contentPadding: const EdgeInsets.all(14), ), ),**

Upvotes: 1

Views: 1096

Answers (2)

Krina chauhan
Krina chauhan

Reputation: 97

add it to init State or in any SetState

gstController.value = TextEditingValue(text: "ANY TEXT");

Upvotes: 0

Nikunj Ramani
Nikunj Ramani

Reputation: 446

you can follow this example

  TextEditingController textEditingController = TextEditingController();

  TextFormField(
    controller: textEditingController,
    autovalidateMode: AutovalidateMode.onUserInteraction,
    style: TextStyle(fontSize: 15),
    decoration: FormFields.getInputDecoration('Email Id'),
  );

the after api response you can set text to textformfield using TextEditingController like this

   setState((){
      textEditingController.text = snapshot.data![index].gSTNo.toString()
   });

Upvotes: 2

Related Questions