Flutter - 将数组添加到小部件列表
Flutter - Adding arrays to a widget list
我想添加申请人列表中的所有数据,但它只添加了数组中的最后一个数据。对不起,我还是 flutter 的新手。
这是我的代码。
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});
}
这是我显示应聘者名单的地方。
Container(
child: StreamBuilder<Object>(
stream: null,
builder: (context, snapshot) {
return Container(
height: MediaQuery.of(context).size.height,
child: ListView(
shrinkWrap: true,
scrollDirection: Axis.vertical,
children: <Widget>[
Column(
children: applicants.map((e) => _PendingCardDonor(e.name, e.contact, e.location),).toList(),
),
],
));
}),
),
我意识到这是因为 List
已被弃用。所以我只需要像这样添加 [] 。 List<ApplicantsList> applicants = [];
我想添加申请人列表中的所有数据,但它只添加了数组中的最后一个数据。对不起,我还是 flutter 的新手。
这是我的代码。
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});
}
这是我显示应聘者名单的地方。
Container(
child: StreamBuilder<Object>(
stream: null,
builder: (context, snapshot) {
return Container(
height: MediaQuery.of(context).size.height,
child: ListView(
shrinkWrap: true,
scrollDirection: Axis.vertical,
children: <Widget>[
Column(
children: applicants.map((e) => _PendingCardDonor(e.name, e.contact, e.location),).toList(),
),
],
));
}),
),
我意识到这是因为 List
已被弃用。所以我只需要像这样添加 [] 。 List<ApplicantsList> applicants = [];