Types of items

To represent different types of items in a list, define
a class for each type of item.

In this example, create an app that shows a header followed by five
messages. Therefore, create three classes: ListItem, HeadingItem,
and MessageItem.

Create a list of items

Most of the time, you would fetch data from the internet or a local
database and convert that data into a list of items.

For this example, generate a list of items to work with. The list
contains a header followed by five messages. Each message has one
of 3 types: ListItem, HeadingItem, or MessageItem.

2. Convert the data source into a list of widgets

To convert each item into a widget,
use the ListView.builder() constructor.

In general, provide a builder function that checks for what type
of item you’re dealing with, and returns the appropriate widget
for that type of item.

Interactive example