Dart convert int variable to string

DartFlutter

Dart Problem Overview


I'm trying to convert an integer variable

var int counter = 0;

into a string variable

var String $counter = "0";

I searched but I only found something like

var myInt = int.parse('12345');

that doesn't work with

var myInt = int.parse(counter);

Dart Solutions


Solution 1 - Dart

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';

Solution 2 - Dart

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

Solution 3 - Dart

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionattilaView Question on Stackoverflow
Solution 1 - DartRichard HeapView Answer on Stackoverflow
Solution 2 - Dartbradib0yView Answer on Stackoverflow
Solution 3 - DartAchintha IsuruView Answer on Stackoverflow