尝试一下:
Locations allLocations(AsyncSnapshot<Results> snap) {
List returnedList = new List();
for (var i = 0; i < snap.data.locationList.length; i++) {
returnedList.add(snap.data.locationList[i]);
}
return returnedList;
}
,
一定不要在每个索引处返回值,否则,该函数将仅在第一个索引处返回,并且不会经历完整的迭代。相反,您应该在循环外返回完整列表。
List<Locations> mList= new List();
Locations allLocations(AsyncSnapshot<Results> snap) {
for(var i in snap.data.locationList){
mList.add(return snap.data.locationList[i]);
}
return snap.data.locationList;
}
,
我想你想要这样的东西
Stream<int> allInts(List<int> list) async* {
for (var i = 0; i < list.length; i++) {
yield list.elementAt(i);
}
}
当我使用这个
allInts(<int>[1,3,5,7,9]).listen((number) {
print(number);
});
控制台:
I/flutter (24597): 1
I/flutter (24597): 3
I/flutter (24597): 5
I/flutter (24597): 7
I/flutter (24597): 9
本文链接:https://www.f2er.com/3014371.html