variables
normal
var, null, late;
var name = 'Bob';
Object name = 'Bob';
String name = 'Bob';
String? name = 'Bob';
int? lineCount;
assert(lineCount == null);
int lineCount2 = 0;
late String description;
void main() {
description = 'Feijoada!';
print(description);
}
// This is the program's only call to readThermometer().
late String temperature = readThermometer();
final & const
Although a final object cannot be modified, its fields can be changed. In comparison, a const object and its fields cannot be changed: they’re immutable.
final name = 'Bob'; // Without a type annotation
final String nickname = 'Bobby';
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.
operators
整除 ~/
assert(2