Back

Related to Realtime

  • 0
  • Flutter
  • Realtime
Joshima
12 Jun, 2023, 11:12

In this post - https://discordapp.com/channels/564160730845151244/1116298067050774568 I was having a problem related to getting my posts appear in real time on homepage and when i made sure that the user id is not null then it started working but now when i open my comment section(where i tried to implement the same) i get this on my debug console - I/flutter (26502): subscription: null and it stops working in post, comment and on other pages -

TL;DR
The user is asking if they can remove Realtime from a provider to fix their issue. They provided code snippets for context. They also mentioned that when they made sure the user ID is not null, the Realtime started working again. However, when they open the comment section, they receive a "subscription: null" error and it stops working on other pages as well. Solution: It is recommended to keep Realtime in the provider to maintain the functionality. To fix the issue with the "subscription: null" error, you may need to troubleshoot the code in the comments section and ensure that the subscription is being properly initialized and passed
Joshima
12 Jun, 2023, 11:17

here is my comments page -

TypeScript
return currentUser == null
    ? const Loader()
    : Scaffold(
      body: Column(
        children: [
          BlogCard(blog: blog),
          ref.watch(getReplyToBlogsProvider(blog)).when(
              data: (comments) {
                return 
ref.watch(getLastestReplytoBlogsProvider).when(
                    data: (data) {
                      if (data.events.contains(
                          'databases.*.collections.${AppConstants.APPWRITE_COMMENTS_COLLECTION}.documents.*.create'
                          )) {
                        comments.insert(0, Comments.fromMap(data.payload));
                      }
                      return Expanded(
                        child: ListView.builder(
                            itemCount: comments.length,
                            itemBuilder: (BuildContext context, int index) {
                              final comment = comments[index];
                              return CommentCard(comment: comment);
                            }),
                      );
                    },
                    error: (error, StackTrace) =>
                        ErrorText(error: error.toString()),
                    loading: () {
                      return Expanded(
                        child: ListView.builder(
                            itemCount: comments.length,
                            itemBuilder: (BuildContext context, int index) {
                              final comment = comments[index];
                              return CommentCard(comment: comment);
                          }),);});},
error: (error, StackTrace) => ErrorText(error: error.toString()),
loading: () => const Loader()),
],),
      bottomNavigationBar: TextField(onSubmitted: (value) {ref.read(CommentsControllerProvider.notifier).shareComment(text: value, context: context, BlogID: blog.id, currentUser: currentUser);
       },),);```
Joshima
12 Jun, 2023, 11:17

realtime provider -

TypeScript
  final BlogAPI = ref.watch(blogAPIProvider);
  return BlogAPI.getLatestReplytoBlogs();
});```
api function - 
```  @override
  Stream<RealtimeMessage> getLatestReplytoBlogs() {
    return _realtime.subscribe([
      'databases.${AppConstants.APPWRITE_DATABASE_ID}.collections.${AppConstants.APPWRITE_COMMENTS_COLLECTION}.documents'
    ]).stream;
  }```
Joshima
12 Jun, 2023, 11:18

(used currentUser provider to make sure if the user is not null[same as i used in post and it started working])

Drake
12 Jun, 2023, 14:34

can you try without putting Realtime in a provider?

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