Andrei
Andrei

Reputation: 936

Flutter save text in textfielf

I am trying to create a kind of forum using text fields. The thing is that when you fill in the blacks and press next and than you go back again, the text field will appear empty as if you have no value in it but its actually saved. I want it so that you can see what you entered inside even if you go forward and than back. I will attach some photos so you can understand better what i mean.

Here is the photo of the text field: https://gyazo.com/9ceb0ef4f27db1be842cbdfac885fc01

In this photo i fill in the blanks: https://gyazo.com/6365ab3fcc9d8167a1c9163563fbf3d7

Than i go forward: https://gyazo.com/8490115e74b57e96cd1f3a9486db5fad

And when i go back again, the text field looks empty but the value is not empty, i want it so that i can still see the value inside: https://gyazo.com/07eec4c58149641926d7f037bb0f949c

Here i will put the code of the TextFIeld:

Container(
          margin: EdgeInsets.only(top: 20),
          width: 360,
          child:
          Form(
            autovalidateMode: AutovalidateMode.always,
            onChanged: () {
              
              Form.of(primaryFocus.context).save();

            },
            child: TextFormField(
              decoration: new InputDecoration(
                labelText: "Event Name",
                fillColor: Colors.white,
                border: new OutlineInputBorder(
                  borderRadius: new BorderRadius.circular(25.0),
                  borderSide: new BorderSide(),
                ),
                //fillColor: Colors.green
              ),
              validator: (val) {
                
                if (val.length == 0) {
                
                
                  return "Event Name cannot be empty";
                  
                } else {
                 
                  return null;
                  
                }
              },
              onSaved: (String value) {
                eventname = value;
              },
              style: new TextStyle(
                fontFamily: "Poppins",
              ))))

Upvotes: 0

Views: 55

Answers (1)

javachipper
javachipper

Reputation: 537

add an initial value to your textformfield by loading the saved value

Upvotes: 1

Related Questions