A basic Dart program
Domains:
Dart
The following code uses many of Dart’s most basic features:
printInteger(int aNumber) // Define a function.
{
print('The number is $aNumber.'); // Print to console.
}
// This is where the app starts executing.
main()
{
var number = 42; // Declare and initialize a variable.
printInteger(number); // Call a function.
}
Here’s what this program uses that applies to all (or almost all) Dart apps:
-
// This is a comment(A single-line comment. Dart also supports multi-line and document comments. For details, see Comments) -
int A type(Some of the other built-in types areString,List, andbool) -
42(A number literal. Number literals are a kind of compile-time constant) -
print() (A handy way to display output) -
'...'(or"...") (A string literal) -
$variableName(or${expression}) (String interpolation: including a variable or expression’s string equivalent inside of a string literal. For more information, see Strings) -
main()(The special, required, top-level function where app execution starts. For more information, see The main() function) -
var A (Way to declare a variable without specifying its type)
Semantic portal