Comments (18)
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
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.
@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
from supabase-dart.
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;
from supabase-dart.
Hello @dshukertjr , yeah o confirm that I enabled all real time functions
from supabase-dart.
@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.
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.
@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.
@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.
@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?
from supabase-dart.
@dshukertjr
Did you mean that ?
from supabase-dart.
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.
@StevePhuc
How did you solve the problem?
from supabase-dart.
@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.
@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.
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.
![]()
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 tofull
. If it's possible, could you share the SQL you used to create yourchat
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
from supabase-dart.
@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.
- Go to
Database
>Replication
and check everything .
- Check that the table at which you want to listen to realtime events are turned on. If not, turn it on.
- 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.
@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.
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.
Also, do you have a public repo that I can take a look at where your working code is stored?
from supabase-dart.
@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)
- Status 404 with returned public url HOT 2
- Resending OTP HOT 2
- Functions-dart repo is not public yet HOT 1
- Dart library rework HOT 1
- Token leaked in network tab HOT 3
- can not update phone number via auth.update() HOT 1
- getx +supabase HOT 4
- Implementation `Column is in an array` HOT 3
- Dart client unable utilize eq() or match() to retrieve a row from table
- RealtimeSubscription Unhandled Exception: type 'Null' is not a subtype of type 'List<dynamic>' in type cast HOT 10
- Int column turned to String in realtime listening (for one row) HOT 6
- Boolean values comes with null in realtime events HOT 2
- Bug: flags field is missing on RLS-Realtime HOT 13
- Kong Error : No Api key found in request HOT 7
- On Stream: The new updated value/row is always replacing the first element of return List of rows. HOT 1
- Can't use `StreamSubscription` with realtime streams HOT 1
- Supabase doesnot export gotrue_error.dart class HOT 1
- Kong Error : No Api key found in request HOT 2
- stream returns invalid response HOT 5
- Unhandled Exception with realtime rls HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supabase-dart.