I have a streambuilder that loads information from firestore. Then I use a listview.builder to display the information. The displayed information is being called by the function
I solved the issue by turning firstBuildItem widget function into a stateful widget of it's own class. And then passing a key to the function. With this, setState worked without rebuilding the entire streambuilder.
ListView.builder(
padding: EdgeInsets.all(10.0),
itemCount: snapshot.data.documents.length,
reverse: true,
controller: listScrollController,
itemBuilder: (context, index) =>
index == snapLength ?
FirstChatBuildMessageItem(
key: Key('counter-${index}'),
id: id,
peerAvatar: peerAvatar,
index: index,
mainDocument: snapshot.data.documents[index],
listMessage: listMessage,
)
:
//index == 0 ?
ChatBuildMessageItem(
key: Key('counter-${index}'),
id: id,
peerAvatar: peerAvatar,
index: index,
mainDocument: snapshot.data.documents[index],
previousDocument: snapshot.data.documents[index + 1],
listMessage: listMessage,
),
),