如何替换已弃用的列表 [英] How to replace deprecated List
问题描述
列表已被弃用.我如何重写以下代码?
RosterToView.fromJson(Map json) {if (json['value'] != null) {rvRows = new List();json['value'].forEach((v) {rvRows.add(new RVRows.fromJson(v));});}}
根据官方文档:
<块引用>@Deprecated(改用列表文字、[] 或 List.filled 构造函数")
<块引用>
注意:此构造函数不能在空安全代码中使用.使用 List.filled 创建一个非空列表.这需要一个填充值来初始化列表元素.要创建空列表,请对可增长列表使用 [] 或对固定长度列表使用 List.empty(或在运行时确定可增长性).
您可以改为这样做:
RosterToView.fromJson(Map json) {if (json['value'] != null) {rvRows = <RVRows>[];json['value'].forEach((v) {rvRows.add(new RVRows.fromJson(v));});}}
另一种选择是:
ListrvRows = [];
List has been deprecated. How do I re-write the following code?
RosterToView.fromJson(Map<String, dynamic> json) {
if (json['value'] != null) {
rvRows = new List<RVRows>();
json['value'].forEach((v) {
rvRows.add(new RVRows.fromJson(v));
});
}
}
According to the official documentation:
@Deprecated("Use a list literal, [], or the List.filled constructor instead")
NOTICE: This constructor cannot be used in null-safe code. Use List.filled to create a non-empty list. This requires a fill value to initialize the list elements with. To create an empty list, use [] for a growable list or List.empty for a fixed length list (or where growability is determined at run-time).
You can do this instead:
RosterToView.fromJson(Map<String, dynamic> json) {
if (json['value'] != null) {
rvRows = <RVRows>[];
json['value'].forEach((v) {
rvRows.add(new RVRows.fromJson(v));
});
}
}
Another option is:
List<RVRows> rvRows = [];
这篇关于如何替换已弃用的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!