Emanuel Developer
Emanuel Developer

Reputation: 708

Changing String to int in onChanged TextForm Field value

Into my TextFormField, I have a onChanged call back to push the value of the variable to the database. At the moment it is a String and I do:

                  TextFormField(
                      style: TextStyle(color: Colors.white,fontSize: 13),
                      keyboardType: TextInputType.number,
                      onChanged: (value) {
                        variableName = value;
                      },

But if I change the variable String to "int" because is a number what I need to do there in onChanged call back?

Upvotes: 2

Views: 945

Answers (1)

Akif
Akif

Reputation: 7640

If you want an int variable, you can simply convert the value in your onChanged method. It will look like this:

            TextFormField(
                  style: TextStyle(color: Colors.white,fontSize: 13),
                  keyboardType: TextInputType.number,
                  onChanged: (value) {
                    variableName = int.parse(value);
                  },

Upvotes: 3

Related Questions