Flutter 如何替换不推荐的列表

Flutter 如何替换不推荐的列表,flutter,dart,Flutter,Dart,该列表已被弃用。如何重新编写以下代码 RosterToView.fromJson(Map<String, dynamic> json) { if (json['value'] != null) { rvRows = new List<RVRows>(); json['value'].forEach((v) { rvRows.add(new RVRows.fromJson(v)); }); } }

该列表已被弃用。如何重新编写以下代码

  RosterToView.fromJson(Map<String, dynamic> json) {
    if (json['value'] != null) {
      rvRows = new List<RVRows>();
      json['value'].forEach((v) {
        rvRows.add(new RVRows.fromJson(v));
      });
    }
  }
RosterToView.fromJson(映射json){
如果(json['value']!=null){
rvRows=新列表();
json['value'].forEach((v){
添加(新的rvRows.fromJson(v));
});
}
}
而不是: rvRows=新列表()

写:
rvRows=[]

错误消息告诉您该怎么做。当我运行
dart analyze
时,我得到:

   info • 'List' is deprecated and shouldn't be used. Use a list literal, [],
          or the List.filled constructor instead at ... • (deprecated_member_use)
          Try replacing the use of the deprecated member with the replacement.
  error • The default 'List' constructor isn't available when null safety is
          enabled at ... • (default_list_constructor)
          Try using a list literal, 'List.filled' or 'List.generate'.
该文件还规定:

此构造函数不能在空安全代码中使用。使用
List.filled
创建非空列表。这需要一个填充值来初始化列表元素。若要创建空列表,请对可增长列表使用
[]
,或对固定长度列表(或在运行时确定可增长性的位置)使用
列表

示例:

var-emptyList=[];
var filledList=List.filled(3,0);//3个元素全部初始化为0。
filledList[0]=0;
已填充列表[1]=1;
填充列表[2]=2;
var filledListWithNulls=List.filled(3,null);
var generatedList=List.generate(3,(索引)=>index);

根据官方文件:

@已弃用(“请改用列表文字、[]或list.filled构造函数”)

注意:此构造函数不能在空安全代码中使用。使用List.filled创建非空列表。这需要一个填充值来初始化列表元素。若要创建空列表,请使用[]表示可增长列表或list.empty表示固定长度列表(或在运行时确定可增长性的位置)

您可以这样做:

RosterToView.fromJson(映射json){
如果(json['value']!=null){
rvRows=[];
json['value'].forEach((v){
添加(新的rvRows.fromJson(v));
});
}
}
另一个选择是:

List<RVRows> rvRows = [];
List rvRows=[];