Home > Mobile >  Flutter: How to store value from flutter textfield as int?
Flutter: How to store value from flutter textfield as int?

Time:06-21

how to store a value from textfield as int so I can use it with operator for calculation?

CodePudding user response:

If you have something like this :

TextEditingController textFieldValue= TextEditingController();

//[...]


TextFormField(
    controller: textFieldValue,
    decoration: const InputDecoration(
        labelText: "Enter an integer :"
    ),
    validator: (value) {
        if (value == null || value.isEmpty) {
            return 'Enter valid data';
        }
        return null;
    },
),

you can use the value with :

var integerFromTextfield = int.parse(textFieldValue.text);

CodePudding user response:

int value=int.parse(textfieldcontrollet.text());

  • Related