Dart Unhandled Exception: FormatException: Invalid radix-10 number (at character 1):-
This error happens when we use the wrong datatype to parse the string to int or double.
Example:-
According to the given picture, if the 45.6 value is a String and we want to parse it into an int or double, we use int parse to parse the string value into an int but the string value is double. that was an error that happened.
If you think that we use double parse to replace int parse, you are right. but it works when we know what data type in the string store like that we know that string of int value then we use int parse.
In some cases, We don't know what datatype comes into this value. I have a solution for it.
Let's get start
See the code below
checkIntDouble(myValue){
if(int.tryParse(myValue) == null){
return double.parse(myValue);
}else{
return int.parse(myValue);
}
}
Use this function where want to parse your value. In this function pass your value in the myValue parameter. after this int.tryParse tried to parse the value if the value is successfully parsed then the value is int and on the other hand int.tryParse returns null then the value is double.