In addition the approach is probably not the best cause it ties together the data class and build method which is less reusable.
Where should this new content appear?
Consider
sealed class ListItem {
}
class HeadingItem extends ListItem {
final String heading;
HeadingItem(this.heading);
}
class MessageItem extends ListItem {
final String sender;
final String body;
MessageItem(this.sender, this.body);
}
class ListItemTitle extends StatelessWidget {}
class ListItemSubTitle extends StatelessWidget {}
ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
return switch(item) {
final HeadingItem _ => ListTile(
title: ListItemTitle(item.heading),
),
final MessageItem _ => ListTile(
title: ListItemTitle(item.sender),
subtitle: ListItemSubtitle(item.body),
)
}
},
)
I would like to fix this problem.
[ ] I will try and fix this problem on docs.flutter.dev.
What information needs to be added?
https://docs.flutter.dev/cookbook/lists/mixed-list is a bit outdated
In addition the approach is probably not the best cause it ties together the data class and build method which is less reusable.
Where should this new content appear?
Consider
I would like to fix this problem.