Friday, October 26, 2018

Flutter: Creating Lists with Different type of Items

The basic design needed for creating list with Different type is

1. Create Data source with Different items
2. Convert the data source into List of widgets

The example here is a list with heading and message items

Abstract class ListItem{}

Class HeadingItem implementes ListItem{
Final String heading;
HeadingItem(this.heading);
}

Class MessageItem implements ListItem {

Final String sender;
Final String body;

MessageItem(this.sender, this.body)
}


Final items = List.generate(
1200,
(i) => I % 6 == 0 ? HeadingItem("Heading Item $I") : MessageItem("Sender $I","Message Body $I")
);
References:
https://flutter.io/cookbook/lists/mixed-list/

No comments:

Post a Comment