Coder Social home page Coder Social logo

Comments (18)

dshukertjr avatar dshukertjr commented on June 22, 2024 2

Thanks @akram-95 for opening this issue and @StevePhuc for also adding more context!

Could you confirm that you have update and delete realtime events turned on in the Supabase console?

https://app.supabase.io/project/[YOUR_PROJECT_ID]/database/replication

Screen Shot 2021-08-17 at 14 36 06

I apologize for not including instructions around turning realtime on in the readme. I will add it as soon as I can get to it!

from supabase-dart.

akram-95 avatar akram-95 commented on June 22, 2024 2

@dshukertjr
It works now , I could know how to solve it
When we create a table and than enable the real-time , it doesn't work perfectly
I needed to delete it and enable real-time and than create the table and it works now perfect
I wanted to share that with you , maybe it can help you to understand the behaviour better

Now I have another issue , I get this error when I use nested Streambuilder image

from supabase-dart.

StevePhuc avatar StevePhuc commented on June 22, 2024

I have the same issue. when insert, new row is insert but the stream is not update
The code I using:

import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

class ChatScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: StreamBuilder(
        stream: Supabase.instance.client
            .from('chat')
            .stream()
            .order('id')
            .limit(30)
            .execute(),
        builder: (ctx, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return Center(
              child: CircularProgressIndicator(),
            );
          }
          final data = snapshot.data! as List;
          print(data);
          return ListView.builder(
            itemCount: data.length,
            itemBuilder: (ctx, index) => Container(
              padding: EdgeInsets.all(8),
              child: Text('${data[index]['id']} ${data[index]['message']}'),
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () async {
          final insertResponse =
              await Supabase.instance.client.from('chat').insert([
            {'message': 'new message'}
          ]).execute();
          if (insertResponse.error == null) {
            print('insertResponse.data: ${insertResponse.data}');
          }
        },
      ),
    );
  }
}

already allow realtime for that table

begin; 
  -- remove the realtime publication
  drop publication if exists supabase_realtime; 

  -- re-create the publication but don't enable it for any tables
  create publication supabase_realtime;  
commit;

-- add a table to the publication 
alter publication supabase_realtime add table chat;

image

from supabase-dart.

akram-95 avatar akram-95 commented on June 22, 2024

Hello @dshukertjr , yeah o confirm that I enabled all real time functions

from supabase-dart.

dshukertjr avatar dshukertjr commented on June 22, 2024

@akram-95
Sorry, please ignore the previous message that you received in your email inbox.

Could you share the scheme of the table at which you are trying to listen to as stream?

from supabase-dart.

StevePhuc avatar StevePhuc commented on June 22, 2024

after update sql with alter table chat replica identity full; it work now. Thanks @dshukertjr

begin; 
  -- remove the realtime publication
  drop publication if exists supabase_realtime; 

  -- re-create the publication but don't enable it for any tables
  create publication supabase_realtime;  
commit;

-- add a table to the publication
alter publication supabase_realtime add table chat;

alter table chat replica identity full;

from supabase-dart.

dshukertjr avatar dshukertjr commented on June 22, 2024

@StevePhuc
I'm glad you were able to fix it. I took down my previous post, because I thought that might not have been the issue, but I guess it was!

@akram-95 Could you also try running?

alter table your_table_name replica identity full;

from supabase-dart.

dshukertjr avatar dshukertjr commented on June 22, 2024

@StevePhuc
Weird is thing is that I actually do not have identity set to full, and yet am able to receive updates and deletes.

When I run

SELECT CASE relreplident
          WHEN 'd' THEN 'default'
          WHEN 'n' THEN 'nothing'
          WHEN 'f' THEN 'full'
          WHEN 'i' THEN 'index'
       END AS replica_identity
FROM pg_class
WHERE oid = 'mytablename'::regclass;

I get default. Could you maybe try to run the above SQL command to see what you get for tables that you haven't set to full yet?

from supabase-dart.

StevePhuc avatar StevePhuc commented on June 22, 2024

@dshukertjr Could you maybe try to run the above SQL command to see what you get for tables that you haven't set to full yet?

image

from supabase-dart.

akram-95 avatar akram-95 commented on June 22, 2024

@dshukertjr
Did you mean that ?
image

image

from supabase-dart.

akram-95 avatar akram-95 commented on June 22, 2024

@StevePhuc

I'm glad you were able to fix it. I took down my previous post, because I thought that might not have been the issue, but I guess it was!

@akram-95 Could you also try running?

alter table your_table_name replica identity full;

When I did run it , I did get no rows gets

from supabase-dart.

akram-95 avatar akram-95 commented on June 22, 2024

@StevePhuc
How did you solve the problem?

from supabase-dart.

dshukertjr avatar dshukertjr commented on June 22, 2024

@akram-95
Sorry, for not being clear. Could you show me your table definition?
If you created your table with SQL, then the SQL code would be better, but if you have created from Supabase's console, then a screenshot is okay. Also if you could let me know which column is the primary key, that would be great.
Screen Shot 2021-08-17 at 19 49 33

@StevePhuc
Thank you so much for sharing your result!
I was further investigating this issue, and it seems like there is a bug where stream() should not work when replica identity is set to full. If it's possible, could you share the SQL you used to create your chat table?

For me, it's working when replica identity is set to default.

from supabase-dart.

akram-95 avatar akram-95 commented on June 22, 2024

@akram-95

Sorry, for not being clear. Could you show me your table definition?

If you created your table with SQL, then the SQL code would be better, but if you have created from Supabase's console, then a screenshot is okay. Also if you could let me know which column is the primary key, that would be great.

Screen Shot 2021-08-17 at 19 49 33

@StevePhuc

Thank you so much for sharing your result!

I was further investigating this issue, and it seems like there is a bug where stream() should not work when replica identity is set to full. If it's possible, could you share the SQL you used to create your chat table?

For me, it's working when replica identity is set to default.

I did create my table from the console
And here the table definition

image

from supabase-dart.

dshukertjr avatar dshukertjr commented on June 22, 2024

@akram-95
I can see that you have an id property, but couldn't really tell the rest. You can take a screenshot by pressing command + Shift + 4 on mac!

Anyway, let me start over. I did create a brand new Supabase project, and was able to receive all Insert, Update, and Delete events with the following steps. Please follow these steps and let me know if they work. It's simple. No need to tweek the replication identity settings or anything.

  1. Go to Database>Replication and check everything .

Screen Shot 2021-08-17 at 20 26 18

2. Click the button inside the red square

Screen Shot 2021-08-17 at 20 26 18

  1. Check that the table at which you want to listen to realtime events are turned on. If not, turn it on.

Screen Shot 2021-08-17 at 20 28 49

  1. Listen to the data using a simple StreamBuilder
StreamBuilder<List<Map<String, dynamic>>>(
  stream: supabase.from('chats').stream().order('id').limit(30).execute(),
  builder: (context, snapshot) {
    if (snapshot.hasError) {
      return Center(child: Text(snapshot.error.toString()));
    }
    if (snapshot.connectionState == ConnectionState.active) {
      final dataList = snapshot.data!;
      return ListView.builder(
        itemCount: dataList.length,
        itemBuilder: (context, index) {
          final data = dataList[index];
          return ListTile(
            title: Text(data['text']),
          );
        },
      );
    } else {
      return Container();
    }
  },
)

from supabase-dart.

akram-95 avatar akram-95 commented on June 22, 2024

@dshukertjr I did make it exactly how you told me
It doesn't update the ui
Here is a video of that https://user-images.githubusercontent.com/55693316/129722286-0e1e3581-f460-4d2d-ad8f-11921457178e.MOV

from supabase-dart.

dshukertjr avatar dshukertjr commented on June 22, 2024

@akram-95

Thanks for sharing a video.
Okay, in that case, could you make sure that you have primary key for your table? When you create a table, you need to have this check box checked.
Screen Shot 2021-08-17 at 21 04 58

Also, do you have a public repo that I can take a look at where your working code is stored?

from supabase-dart.

dshukertjr avatar dshukertjr commented on June 22, 2024

@akram-95
So glad to hear that it is working now. Thanks for sharing the steps you took to make it work. We will work on improving the documentation on how to get started with it.

Thanks for reporting the issue with nested StreamBuilder. Could you actually open another issue for that one?

from supabase-dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.