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, ), ), SizedBox( width: 20, ), InkWell( onTap: () { Navigator.pushNamed( context, '/viewlocation', ); }, child: Icon( Icons.add_location, color: Colors.green, size: 40, ), ), SizedBox( width: 20, ), Container( decoration: BoxDecoration( color: Colors.green, border: Border.all( color: Colors.green, ), borderRadius: BorderRadius.all(Radius.circular(20))), child: InkWell( onTap: () async { const number = '08592119XXXX'; //set the number here bool res = await FlutterPhoneDirectCaller.callNumber( number); }, child: Icon( Icons.call, color: Colors.white, size: 40, ), ), ) ])), ), Divider( color: Colors.black, endIndent: 10, indent: 10, ), ], ), ); } } 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
https://stackoverflow.com/questions/66775054/how-to-iterate-through-list-of-map-and-display-text-widget-in-flutter-listview March 24, 2021 at 01:05PM
没有评论:
发表评论