+ 1
Passing data to list from json in flutter
I am trying to add data to a list in flutter i have a model class Visitors with a method getVisitors as below List<Visitor> _visitors=[] void getVisitors(id, name) { print(name) //to check if im receiving correct data var newVisitor=Visitor(id,name); _visitors.add(newVisitor ) } My function runs and prints a name on the the debug console but when i run _visitors. Length i get 0 which i don't understand because i thought _visitors.add(newVisitor) would push a mew object to the list }
1 Respuesta