Console logging in dart
You,•dart + flutter
Printing to console in dart
void main() {
print("hey there"); //print a string to console
int i =7; //a variable, an integer
double d = 7.89;
print(i); //printing a variable directly
print(d);
}
Console Output:
hey there
7
7.89
Embedding variables inside string
void main() {
int i =22; //a variable, an integer
print("The value of i is $i"); //$i embeds i inside string
print("i + 3 = ${i+3}"); //${} to hold expressions
print('SQ:i + 1 = ${i+1}'); //single quotes OK
}
Console output:
The value of i is 22
i + 3 = 25
SQ:i + 1 = 23
dart prints objects too
void main() {
String s = "super duper"; //a string , note uppercase 'S'
double d = 6.2874; //a double
var o = {"distance" : 334.2, "units": "km" }; //an object
print(s);
print(d);
print(o);
}
super duper
6.2874
{distance: 334.2, units: km}