Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Limit list data in dart

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" ? "&#10003;" : "&#8211;";
                    areaOfInspecHtml += '</td>';

                    areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
                    areaOfInspecHtml += entry['value'].split("#")[1] == "true" ? "&#10003;" : "&#8211;";
                    areaOfInspecHtml += '</td>';

                    areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
                    areaOfInspecHtml += entry['value'].split("#")[2] == "true" ? "&#10003;" : "&#8211;";
                    areaOfInspecHtml += '</td>';

                    areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
                    areaOfInspecHtml += entry['value'].split("#")[3] == "true" ? "&#10003;" : "&#8211;";
                    areaOfInspecHtml += '</td>';
                    areaOfInspecHtml += "</tr>";
                }
            }
            return areaOfInspectionHtml;
        } else {
            log("====*****areaOfInspecHtml not found");
            return '';
        }
    } catch (e) {
        throw Exception("Error" + e.toString());
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)) {
  ...
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading