'How can I add a Widget between items in a list?
Problem:
Hi everyone! I have this "problem" that I want to add a
Widgetbetween the elements but I can't... idk why, here's an example of myListtypeChatMessage:
List<ChatMessage> messages = [
ChatMessage(content: 'Hi!👋', type: 'sent', date: DateTime(2022, 5, 7)),
ChatMessage(content: 'Hello!👋', type: 'received', date: DateTime(2022, 5, 8)),
ChatMessage(content: 'How are you?', type: 'received', date: DateTime(2022, 5, 8)),
ChatMessage(content: 'Im good', type: 'sent', date: DateTime(2022, 5, 9)),
];
Expected:
The result that I want it's similar in the below block (Separated by
DateTimedynamically, basically add this "Widget" between them automatically just with theDateTimecondition)
List<ChatMessage> messages = [
ChatMessage(content: 'Hi!👋', type: 'sent', date: DateTime(2022, 5, 7)), // Day 7
// Some Widget...
ChatMessage(content: 'Hello!👋', type: 'received', date: DateTime(2022, 5, 8)), // Day 8
ChatMessage(content: 'How are you?', type: 'received', date: DateTime(2022, 5, 8)), // Day 8
// Some Widget...
ChatMessage(content: 'Im good', type: 'sent', date: DateTime(2022, 5, 9)), // Day 9
];
Solution 1:[1]
Make Changes to the type of List specified in arrow brackets <>
From this:
List<ChatMessage> messages = [
ChatMessage(content: 'Hi!?', type: 'sent', date: DateTime(2022, 5, 7)),
ChatMessage(content: 'Hello!?', type: 'received', date: DateTime(2022, 5, 8)),
ChatMessage(content: 'How are you?', type: 'received', date: DateTime(2022, 5, 8)),
ChatMessage(content: 'Im good', type: 'sent', date: DateTime(2022, 5, 9)),
];
To this:
List<Widget> messages = [
ChatMessage(content: 'Hi!?', type: 'sent', date: DateTime(2022, 5, 7)), // Day 7
// Some Widget...
ChatMessage(content: 'Hello!?', type: 'received', date: DateTime(2022, 5, 8)), // Day 8
ChatMessage(content: 'How are you?', type: 'received', date: DateTime(2022, 5, 8)), // Day 8
// Some Widget...
ChatMessage(content: 'Im good', type: 'sent', date: DateTime(2022, 5, 9)), // Day 9
];
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pacific |
