Search code examples
flutterdartdouble

How to get the data of TextFormField as a double in flutter


I tried double.parse to get the data of TextFormField as a double:

double _pointsUsing = double.parse(pointsEdditingController.text);

but it causes error saying "The method '>=' was called on null". If I tried this:

double _pointsUsing = double.tryParse(pointsEdditingController.text);

it returns null.

The textformfield text value is: 1,133.00

It also says "Tried calling: <(1133.0) 1,133.00"


Solution

  • you need to remove "," from the string then after parse to double.

    double _pointsUsing = double.parse(pointsEdditingController.text.replaceAll(",",""));