How to Convert String to Number in Flutter
When developing mobile apps we always get into situations where we want to convert data types. In this blog post, let’s check how to convert a string into a number, that is an integer or a double in Flutter.
We can use some Dart functions for this purpose.
String to Integer in Flutter
The string can be converted to an integer using int.parse function. See the code snippet given below.
var stringOne = '1';
var numberOne = int.parse(stringOne);
print(numberOne);
String to Double in Flutter
Sometimes, integers may not be enough and we want decimals from the string. This can be achieved using double.parse function. See the snippet given below.
var stringTwoPointOne = '2.1';
var twoPointOne = double.parse(stringTwoPointOne);
print(twoPointOne);
That’s how you convert String into integer and double in Flutter.