Back

View Not Updating

  • 0
  • Flutter
  • Realtime
Zionnite
5 Mar, 2024, 14:01

I have this code that is called inside the init

TypeScript
  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 view
TL;DR
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.
ideclon
5 Mar, 2024, 14:04

What’s not showing up where?

Zionnite
5 Mar, 2024, 14:04

i want to update my view

Zionnite
5 Mar, 2024, 14:06

if i call the _realtimeSynchronisation() function inside the build() function, it will trigger the realtime functions multiple time

Zionnite
5 Mar, 2024, 14:07

so i thought initialising it inside the initState would be better

ideclon
5 Mar, 2024, 14:27

So what is working, and what isn’t?

Zionnite
5 Mar, 2024, 14:29

if i make a call to the _realtimeSynchronisation() the flutter view will be updated but the issues is that it will be called multiple time

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more