Simple ways of converting types in dart.
We want to convert a string to a number(int).
We use the parseInt method.
| void main(){
var myInt = int.parse('12345');
assert(myInt is int);
print(myInt); // 12345
}
|
| void main(){
var myString = (12345).toString;
print(myString); // '12345'
}
|
| void main(){
var myDouble = double.parse('12345');
print(myDouble); // 12345.0
}
|
| void main(){
var myDouble = (12345).toDouble();
print(myDouble); // 12345.0
}
|
| void main(){
var myRadixString = (12345).toRadixString(2);
print(myRadixString); // 11000000111001
}
|
For more dart types conversions, check this link.. https://api.dartlang.org/stable/2.3.1/dart-core/num-class.html#instance-methods