Flutter convert int variable to string

2020-03-13 07:58发布

I'm new with Flutter and I wonder about how difficult is (for me) to find a solution on how to convert my variable var int counter = 0; into a variable var String $counter = "0";

I searched a lot but more at all I only found something like var myInt = int.parse('12345');

that doesn't work with var myInt = int.parse(counter);

标签: dart flutter
3条回答
你好瞎i
2楼-- · 2020-03-13 08:31

You can use the .toString() function in the int class.

int age = 23;
String tempAge = age.toString();

then you can simply covert integers to the Strings.

查看更多
够拽才男人
3楼-- · 2020-03-13 08:37

// 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

查看更多
乱世女痞
4楼-- · 2020-03-13 08:47

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';
查看更多
登录 后发表回答