Flutter - 将数组添加到小部件列表

问题描述

我想添加申请人列表中的所有数据,但它只添加数组中的最后一个数据。抱歉,我还是新手。

这是我的代码

rbenv

这是我的申请人名单

List<ApplicantsList> applicants;

Future <void> getApplicantInfo() async {

  AuthService().getRequestorApplicants().then((val) async {    
    for (var i = 0; i < val.data.length; i++) {
      var temp = val.data[i];
      applicants = [
        ApplicantsList(name: temp['parentname'],contact: temp['parentname'],location: temp['location'])
      ];
    }    
  }); 
}

这是我显示申请人名单的地方。

class ApplicantsList {
  String name;
  String contact;
  String location;

  ApplicantsList({this.name,this.contact,this.location});
}

解决方法

我意识到这是因为 List 已被弃用。所以我只需要像这样添加 [] 。 List<ApplicantsList> applicants = [];