Back

Unable to update stateNotifier when realtime data arrives

  • 0
  • Flutter
  • Realtime
  • Cloud
Drake
29 Aug, 2023, 01:11

What is your code?

TL;DR
User is experiencing an issue with updating stateNotifier when realtime data arrives. The error suggests that the provider cannot be modified in a build function. The user's code includes a stream provider and a method to get the latest message using realtime data. Another user asks for the user's code.
Nuaiman
29 Aug, 2023, 01:12

Just a moment

Nuaiman
29 Aug, 2023, 01:15

@Steven

Nuaiman
29 Aug, 2023, 01:15
Nuaiman
29 Aug, 2023, 01:16

Stream<RealtimeMessage> getLatestMessage();

TypeScript
  Stream<RealtimeMessage> getLatestMessage() {
    final realtime = _realtime.subscribe([
      'databases.${AppwriteConstants.databaseId}.collections.${AppwriteConstants.messagesCollection}.documents'
    ]).stream;
    return realtime;
  }
Nuaiman
29 Aug, 2023, 01:17

final getLatestMessageProvider = StreamProvider((ref) { final chatApi = ref.watch(chatsApiProvider); return chatApi.getLatestMessage(); });

Drake
29 Aug, 2023, 01:51

As the error says, you can't modify the provider in a build function

Drake
29 Aug, 2023, 01:51

The error even gives you suggestions for what to do

Nuaiman
29 Aug, 2023, 01:52

Thankyou

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