scarcoco / projx

5 stars 0 forks source link

dart overview #5

Open scarcoco opened 5 years ago

scarcoco commented 5 years ago

dart overview

示例

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

重要概念

image

变量

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.