Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart convert int variable to string

Tags:

flutter

dart

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); 
like image 295
attila Avatar asked Mar 02 '19 00:03

attila


People also ask

How do you convert int to String in darts?

Use the toString() method to convert an int or double to a string. To specify the number of digits to the right of the decimal, use toStringAsFixed(). To specify the number of significant digits in the string, use toStringAsPrecision(): // Convert an int to a string.

How do you convert an integer to a String flutter?

To convert int variable to string in Flutter All You need to do is Just use the toString() method to convert int to string. Here is an Example. To convert int variable to string in Flutter All You need to do is Just use the toString() method to convert int to string.

How do you use a variable in a String Dart?

If you are attempting to put a String variable inside another static String you can do the following for simple variables: String firstString = 'sentence'; String secondString = 'This is a $firstString'; Which will output This is a sentence .


2 Answers

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'; 
like image 140
Richard Heap Avatar answered Oct 02 '22 13:10

Richard Heap


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

like image 31
bradib0y Avatar answered Oct 02 '22 14:10

bradib0y