I want to limit list in for in loop. if data list more than 8. It just display 8 list. I’ve add condition like this if (entry.length <= 8) but it not working.
poweredareaOfInspec(List < Map < String, dynamic >> areaOfInspec) {
try {
if (areaOfInspec != null) {
var areaOfInspecHtml = "";
for (var entry in areaOfInspec) {
if (entry.length <= 8) {
areaOfInspecHtml += '<tr style="height: 35px;">';
areaOfInspecHtml +=
'<td align="center" style="font-family: arial; color: #414141;font-size: 12px;border-right: solid 0.7px #d6d5d5;">' +
entry['key'] +
'</td>';
areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
areaOfInspecHtml += entry['value'].split("#")[0] == "true" ? "✓" : "–";
areaOfInspecHtml += '</td>';
areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
areaOfInspecHtml += entry['value'].split("#")[1] == "true" ? "✓" : "–";
areaOfInspecHtml += '</td>';
areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
areaOfInspecHtml += entry['value'].split("#")[2] == "true" ? "✓" : "–";
areaOfInspecHtml += '</td>';
areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
areaOfInspecHtml += entry['value'].split("#")[3] == "true" ? "✓" : "–";
areaOfInspecHtml += '</td>';
areaOfInspecHtml += "</tr>";
}
}
return areaOfInspectionHtml;
} else {
log("====*****areaOfInspecHtml not found");
return '';
}
} catch (e) {
throw Exception("Error" + e.toString());
}
}
>Solution :
Use take. It will return the first N items in a list (or all of them if the list has N or less items):
for (var entry in areaOfInspec.take(8)) {
...
}