Reputation: 6766
array arr = [MenuItem1, MenuItem2, MenuItem3]
class MenuItem{
String desc;
String id;
}
For the above class and array, how would I present them as a dynamic list flutter?
Rows of Row(chidren[Text((desc),Text((id)])
;
Upvotes: 4
Views: 7824
Reputation: 271
This code will help you to update the list dynamically.
ListView.builder(
itemCount: arr.length,
itemBuilder: (_, index) {
return Row(
children: <Widget>[Text(arr[index].desc), Text(arr[index].id)],
);
},
)
Upvotes: 2
Reputation: 3768
After Dart 2.3 you can use Collection For:
return Row(children:
[for (MenuItem item in arr ) Text(item.desc)]
);
Since you want to return 2 Widgets for each item in the array, you can combine this with the Spread operator:
return Row(children:
[for (MenuItem item in arr ) ...[Text(item.desc),Text(item.id)]]
);
Upvotes: 5