Use toString and/or toRadixString
int intValue = 1;
String stringValue = intValue.toString();
String hexValue = intValue.toRadixString(16);
or, as in the commment
String anotherValue = 'the value is $intValue';
Answer from Richard Heap on Stack OverflowUse toString and/or toRadixString
int intValue = 1;
String stringValue = intValue.toString();
String hexValue = intValue.toRadixString(16);
or, as in the commment
String anotherValue = 'the value is $intValue';
// String to int
String s = "45";
int i = int.parse(s);
// int to String
int j = 45;
String t = "$j";
// If the latter one looks weird, look into string interpolation on https://dart.dev
Videos
You can parse a string into an integer with int.parse(). For example:
var myInt = int.parse('12345');
assert(myInt is int);
print(myInt); // 12345
Note that int.parse() accepts 0x prefixed strings. Otherwise the input is treated as base-10.
You can parse a string into a double with double.parse(). For example:
var myDouble = double.parse('123.45');
assert(myDouble is double);
print(myDouble); // 123.45
parse() will throw FormatException if it cannot parse the input.
In Dart 2 int.tryParse is available.
It returns null for invalid inputs instead of throwing. You can use it like this:
int val = int.tryParse(text) ?? defaultValue;
You can use join method to do so.
print(integers.join(","));
The shortest answer is
integers.join(',');
If you want more control over the operation where let's say you want to do additional computation at each iteration you can use this:
List<int> integers=[4, 5];
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < integers.length; i++) {
buffer.write(integers[i].toString() + ',');
}
//REMOVE LAST COMMA
String values = '';
if (integers.length > 0)
values = buffer.toString().substring(0, buffer.length -1);
print(values);