Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get input of text controller as a double? - flutter

I have a textcontroller and need to pass the text controller value to a parameter of a class that only accepts double as the input but by default the type of textcontroller is string.

Text Controller:

 TextEditingController priceController = TextEditingController();
 ...
 child: TextField(
              controller: priceController,
              keyboardType: TextInputType.number,
              autofocus: true,
            ),

Passing in the value go priceController to the parameters that accepts only double value:

LevelEventCreate(price: priceController.text);

However the parameters does not accept the value of priceController.text as it is a string. Any way to change it to a double value instead?

like image 484
irongirl Avatar asked Apr 22 '19 07:04

irongirl


1 Answers

I finally figured the answer.

So I just parse it as a double into the parameters of the class instead.

LevelEventCreate(price: double.parse(targetPriceController.text)),
like image 164
irongirl Avatar answered Oct 05 '22 07:10

irongirl