ZionniteOriginal post
Rank 3: Container
I have this code that is called inside the init
Plain text
void initState() { super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) { initialization(context); _realtimeSynchronisation(); }); }```
**_realtimeSynchronisation** ```_realtimeSynchronisation() { print('SYNC CALLED'); ref.watch(getLatestChatMsgProvider).when( data: (data) { final message = MessageAppwrite.fromJson(data.payload); final document = Document.fromMap(data.payload);
var event = ''; if (data.events.contains('databases.*.collections.${Strings.collectionMessagesId}.documents.*.create')) { event = 'create'; } else if (data.events.contains('databases.*.collections.${Strings.collectionMessagesId}.documents.*.delete')) { event = 'delete'; } else if (data.events.contains('databases.*.collections.${Strings.collectionMessagesId}.documents.*.update')) { event = 'update'; } else { event = 'loading'; }
print('outer income'); if ((message.senderUserId == myUserId message.receiverUserId == myUserId) && (message.senderUserId == friendUserId message.receiverUserId == friendUserId)) { print('incomes here'); print('Message Sent is ${message.message}'); print('Event $event'); messageNotifier?.saveMessage(message, document, event); } }, error: (error, stk) => ErrorText(error: error.toString()), loading: () => print('SYNC CALLED how'), );
setState(() {}); }```
Everything is working but it's not showing up in viewSummary
Developers are facing difficulty in updating their view after calling the **_realtimeSynchronisation()** function. Although initializing it in the **initState** works, calling it in the **build** function triggers it multiple times. The goal is to update the view every time the function is triggered.
**Solution:** The issue seems to be related to the logic flow and the function being called inappropriately. It's advised to carefully manage the function calls and ensure they are triggered only when required to update the view properly.