I’m currently working on a Flutter project using Supabase as the backend. I’m trying to implement a stream on RPC (Remote Procedure Call) functions to receive real-time updates, but I’m facing issues.
I’ve tried using the asStream() method, but it doesn’t seem to stream changes as expected. Can someone guide me on how to properly implement streaming on RPC functions in Flutter Supabase to receive real-time updates? Any help or code examples would be appreciated.
Issue: Its working like future. If there is a change in DB it doesn’t update UI or even print(‘Yes’)
Thank you!
Here the code
Stream readSteam() {
return supabase
.rpc(
'read_guest_count',
params: {
'param_user_id': currentUuid,
},
)
.asStream()
.doOnDone(
() => print('Yes'),
);
}
Widget
StreamBuilder(
stream: readSteam(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
// While waiting for data, display a loading indicator or placeholder
return Text(
'Loading...',
style: TextStyle(fontSize: 9),
);
} else if (snapshot.hasError) {
// If there's an error with the stream, display an error message
return Text(
'Error: ${snapshot.error}',
style: TextStyle(fontSize: 9),
);
} else {
// If the stream has data, display the data in the Text widget
final List<dynamic>? count =
snapshot.data as List<dynamic>?;
int totalGuests =
count![0]['total_guests'];
return Text(
'$totalGuests',
style: TextStyle(fontSize: 9),
);
}
},
)
2
Answers
here is a suggestion for u ..
try this i am not a expert hope it will help
Streaming realtime updates from a rpc function in Supabase is simply impossible. Currently in Supabase, you can only listen to realtime updates on a single table. That is the limitation.
Depending on what you are trying to do, there is always a workaround to achieve it with how Supabase works. If you can share more of your particular use case, and what exactly you are trying to achieve, I can guide you to a solution that might work.