I'm very new to flutter I'm trying to display listview through for loop from the list of contents but I was able to print one list row which is one iteration as return fires only once. How to iterate through the complete list and display all listview elements? below is the list of map content
List<Map<String, String>> users = [
{"name": "Staff 1", "status": "Online"},
{"name": "Staff 2", "status": "Online"},
{"name": "Staff 3", "status": "Offline"},
{"name": "Vehicle 1", "status": "Available"},
{"name": "Vehicle 2", "status": "Unavailable"},
{"name": "Team 1", "status": "Active"},
{"name": "Team 2", "status": "Not Active"},
];
below is the code for the listview widget which I'm trying to display
Widget ListViewBuilder() {
for (var i = 0; i < users.length; i++) {
print(i);
return Expanded(
child: ListView(
children: <Widget>[
GestureDetector(
onTap: () {
Navigator.pushNamed(
context,
'/chatscreen',
);
},
child: ListTile(
leading: CircleAvatar(
radius: 20,
backgroundImage: AssetImage("assets/profileavatar.png")),
title: Text(users[i]['name']),
subtitle: Text("User -ID"),
trailing: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween, // added line
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
users[i]['status'],
style: TextStyle(
color: Colors.green,
fontSize: 20,
),
),
],
),
);
}
}
this will display only first element in the list, how can I achieve to display all listview elements present in list users? any advice will be helpful
