Home > Enterprise >  How can I do math for values ​given in TextEditingController?
How can I do math for values ​given in TextEditingController?

Time:12-06

    late final TextEditingController _weight = TextEditingController()
  late final TextEditingController _height = TextEditingController()

For example, for these two TextEditingControllers, I want to collect the values ​​entered by the user and print them in Text. How do I code this?

CodePudding user response:

You can use the text property of the TextEditingController to get the values entered by the user. For example, you can use the following code to print the values entered by the user in a Text widget:

Text('Weight: ${_weight.text} \nHeight: ${_height.text}')

CodePudding user response:

You access the text by checking the text property. In your example, e.g.:

_weight.text

CodePudding user response:

You can try to parse text property like this:

final _weightValue = double.tryParse(_weight.text);
final _heightValue = double.tryParse(_height.text);

I suggest you force keyboard to insert only numbers with:

keyboardType: TextInputType.number

in your TextField

  • Related