List
具有一定长度存在索引的对象集合(长度为0不存在索引,长度>0存在索引)
常见列表
1、定长列表
默认值null
例如:List fixedLengthList = new List(2)、List fixedLengthList = new List(8)
List fixedLengthList = new List(2);
for(int i=0;i<2;i++){
print("索引为${i}的值${fixedLengthList[i]}");
}
I/flutter ( 9251): 索引为0的值null
I/flutter ( 9251): 索引为1的值null
固定长度不可修改
List fixedLengthList = new List(2);
//改变固定数组长度
fixedLengthList.length=30;
Unsupported operation: Cannot change the length of a fixed-length list
大概意思:无法更改固定长度数组的长度
List fixedLengthList = new List(2);
///执行添加数据操作
fixedLengthList.add(0);
fixedLengthList.add(1);
List fixedLengthList = new List(2);
fixedLengthList[0]=1;
fixedLengthList[1]=2;
///添加数据
fixedLengthList.addAll([3,4]);
Unsupported operation: Cannot add to a fixed-length list
大概以上: 不能添加数据到固定长度数组
List fixedLengthList = new List(2);
//执行插入数据