Search code examples
jsonflutterdartdart-pubdart-null-safety

populating list with another list in flutter


I have a list of object and I want populate the list with another dynamic list using for each , so when I try to do so only the last value from the dynamic list is added to the other list..

some one please help

 var keylist =[1,2] ;
 for (var key in keylist) {

_devchanged=[



   Employeemodal(
   
       developer: key
   
    
       )

       ];
        }

Solution

  • You can use .add like this

    var keylist =[1,2] ;
    List<Employeemodal> _devchanged = [];
    
     for (var key in keylist) {
        _devchanged.add(Employeemodal(developer: key));
    }