I am making a http request:
tempEvses.addAll(newItems.map<Evse>((items) {
final evseID = items['evseID'];
final friendlyName = items['friendlyName'];
final registrationStatus = items['registrationStatus'];
final street = items['street'];
final streetNumber = items['streetNumber'];
final region = items['region'];
final lat = items['latitude'] ?? 0.0;
final lng = items['longitude'] ?? 0.0;
final connectorList = items['connectorWSList'];
final cpSerial = items['cpSerial'];
final img = items['img'];
return new Evse(evseID: evseID, friendlyName: friendlyName,registrationStatus:registrationStatus, street: street, streetNumber: streetNumber, region: region, lat: lat, lng: lng, connectorList: connectorList, cpSerial: cpSerial, img: img);
}).toList());
if registrationStatus='Pending'
then no one of items should enter the list. How can i do that?
CodePudding user response:
With for loop
you can achieve this:
List result = [];
for (var items in newItems) {
final evseID = items['evseID'];
final friendlyName = items['friendlyName'];
final registrationStatus = items['registrationStatus'];
final street = items['street'];
final streetNumber = items['streetNumber'];
final region = items['region'];
final lat = items['latitude'] ?? 0.0;
final lng = items['longitude'] ?? 0.0;
final connectorList = items['connectorWSList'];
final cpSerial = items['cpSerial'];
final img = items['img'];
if (registrationStatus == 'Pending') {
result.add(new Evse(
evseID: evseID,
friendlyName: friendlyName,
registrationStatus: registrationStatus,
street: street,
streetNumber: streetNumber,
region: region,
lat: lat,
lng: lng,
connectorList: connectorList,
cpSerial: cpSerial,
img: img));
}
}
tempEvses.addAll(result);