Unable to unsubscribe or remove subscribed channels from Supabase realtime

Custom Code

Hello Flutterflow friends,
Currently, I am able to successfully subscribe to INSERT event in my Supabase table by using custom action. But having problem with unsubscribe.

In Flutterflow main.dart, SupaFlow is initialized by default.

CASE 1:

If I directly use it for subscribe and unsubscribe (Note SupaFlow in default does not include accessToken), subscribe works when RLS in supabase turned off (SELECT won't check for authenticated users). However, I am only able to do remove all channels in unsubscribe code. unsubscribe/remove a specific channel won't work.
***My guess is I need to set up a global object for storing subscribed channel instance for unsubscribe code to find the same channel, so that it can do unsubscribe/remove. Flutterflow does not support such function as of now?***

subscribe code:

unsubscribe code:

CASE 2:

If I add accessToken into headers and redefine the initilization of supaFlow.client called supabaseClient, then the subscribe works with RLS turned on. However, unsubscribe would not work when I do removeAll channel (won't work for specific channel either). Maybe they have to initilize in global main.dart?

Subscribe code:

Unsubscribe code:


It would be better if I can subscribe with accessToken and unsubscribe to that specific channel. But I am also happy if I can subscribe with accessToken and unsubscribe all channel. Because I think it would be better to turn RLS on for authentication. Note sure why it is not an option for Flutterflow default.

Can someone please help me with this? Many Thanks!

What have you tried so far?

For CASE 2, SupabaseClient.removeAllChannels() works if I directly append to the subscribe code:

At the same time, supbaseClient.channel('public:$table').unsubscribe would NOT work if I append to subscribe code.

I think it indicates I need to put them into main.dart for initialize?

Did you check FlutterFlow's Documentation for this topic?
Yes
7
1 reply