9

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?

1 Answer 1

28

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)),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.