How to Convert the Int to a String in Dart
In this tutorial, we are going to learn about how to convert the integer (Int) to an string in Dart with the help of examples.
Consider, we have a following integer in our code:
var a = 20
Now, we need to convert the above integer 20
to a string "20"
.
Using toString() method
To convert a string to an integer, we can use the built-in toString()
method in Dart.
The toString()
method returns the string representation of an integer.
Here is an example:
void main() {
var a = 20;
var result = a.toString(); // converts int to string
print(result);
}
Output:
"20"
Or we can use the string interpolation in Dart.
void main() {
var a = 20;
var result = "$a"; // converts int to string
print(result);
}