Flutter 升级到 2.2 后发现使用 new List()
来创建一个新的集合 的方式 显示成弃用了
替换方案:
List<String> list = [];
或
List<String> list = List.empty(growable: true);
growable
为 false
是为 固定长度列表,为 true
是为 长度可变列表
创建给定长度的列表
要创建具有给定长度的可增长列表,对于可为空元素类型,只需在创建后立即分配长度:
List<int> list = []..length = 3;
对于不可为空的元素类型,替代方法如下:
List<int> growableList = List<int>.filled(3, 0, growable: true);
可参考dart api 文档:https://api.dart.dev/stable/2.13.3/dart-core/List/List.html