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?
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)),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With