// Define a function.
printInteger(int aNumber) {
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.
}
重要概念
变量
var name = 'Bob';
// Object name='Bob';
dynamic name = 'Bob';
String name = 'Bob';
默认值
默认值都是 null
int lineCount
assert(lineCount == null);
final & const
is & as
const Object i = 3; // Where i is a const Object with an int value...
const list = [i as int]; // Use a typecast.
const map = {if (i is int) i: "int"}; // Use is and collection if.
const set = {if (list is List<int>) ...list}; // ...and a spread.
dart overview
示例
重要概念
变量
默认值
默认值都是 null
final & const
is & as