ı am working on chat page like conversation. And ı can fetch data with stream from firebase.When ı open page first time all data come but if new data added to the firebase, my ui not updating. And also when ı go to back and click again to go to conversation page new data coming.
my view model function
Stream<List<Message?>> getSingleConversation(conversationId) async* {
String? userId = await _authRepository.getCurrentUserId();
if (userId != null) {
yield* _conversationRepository.getSingleConversation(
conversationId, userId);
}
}
my provider route
MaterialPageRoute(
builder: (context) => MultiProvider(
providers: [
StreamProvider<List<Message?>>.value(
value: _conversationViewModel.getSingleConversation(chat!.id),
updateShouldNotify: (_, __) => true,
initialData: [],
),
ChangeNotifierProvider.value(value: ConversationViewModel()),
],
child: ConversationPage(
chat: chat,
conversationId: chat.id,
),
),
)
and ui
List<Message?> viewModelProvider = Provider.of<List<Message?>>(context);
Widget _buildMessagesList(List<Message?> viewModelProvider) {
return ListView(
children: viewModelProvider.map((e) {
return _buildMessageCard(e!);
}).toList());
}