dart-数据类型

数字(number)

分为整数和双精度两种

int a = 10;
double c = 0.1;

字符串(string)

一组 UTF-16 单元序列,用双引号或单引号包裹。

String str = "hi";

String multi-line = '''
使用三个单引号
或者三个双引号
'''

布尔值(boolean)

列表(list)

List<int> arr = [1,2,3];

var ls = new List();

// 指定类型后,不能添加其他类型
var ls = new List<String>();

// 获取索引和值
// Use Map Entries
// Convert the List to a Map, then map the entries containing the key/value pairs. Each key in the map is the index of the original list.
myList.asMap().entries.map((entry) {
int idx = entry.key;
String val = entry.value;

return something;
}

// Generate a Fixed Range List
// If you are looping over many lists that have a fixed length, it may be more efficient to generate a single list once. For example, the we create a ranged list that is the same length as the original, i.e. [0, 1, 2, ..., n]

final List fixedList = Iterable<int>.generate(myList.length).toList();


fixedList.map((idx) {
String val = myList[idx];

return something;
}

// Grab the Index of Unique Values
// You can access the index of a specific value by searching for it with List.indexOf, which returns the index of the first match. This approach is most predictable when all values are unique. A Set can ensure uniqueness throughout the list.

final List uniqueList = Set.from(myList).toList();


uniqueList.map((val) {
String idx = uniqueList.indexOf(val);

return something;
}

集合(set)
映射(map)
符文(rune)
符号(Symbol)