Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart : Printing integer along with string

Consider the below code.

void main() {
  int num = 5;
  print('The number is ' + num);
}

When I try to print the value for the variable num, I get the exception : The argument type 'int' can't be assigned to the parameter type 'String'.

How do I go about in printing num?

like image 205
Arun George Avatar asked Jun 16 '18 07:06

Arun George


People also ask

How do you print an integer and string together in darts?

Just add toString() to your int.

How do you print a string value in darts?

The print() function is used to print the string on the screen. The string can be formatted message, any expression, and any other object. Dart provides ${expression}, which is used to put the value inside a string.

How do you get the int of a string in flutter?

A string can be cast to an integer using the int. parse() method in Dart. The method takes a string as an argument and converts it into an integer.


1 Answers

In order to print the value of the int along with the String you need to use string interpolation:

void main() {
  int num = 5;
  print("The number is $num");
}
like image 192
Pawel Laskowski Avatar answered Oct 29 '22 22:10

Pawel Laskowski