supabase/supabase-dart

`stream` function not working on updates

chimon2000 opened this issue · 4 comments

Bug report

When using the new stream function, database updates are not triggering updates in the application.

Describe the bug

Same as above. Here is a sample where Note is a simple Dart data class and _NotesListView is a simple ListView that creates ListTiles for each note:

class NotesStreamBuilder extends StatelessWidget {
  const NotesStreamBuilder({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: context
          .read(supabaseProvider)
          .from(NotesService.notes)
          .stream()
          .execute()
          .map((results) => results.map((e) => Note.fromMap(e)).toList()),
      builder: (context, AsyncSnapshot<List<Note>> snap) {
        print(snap);
        if (snap.hasError) {
          return Center(
            child: Text('Something bad happened'),
          );
        }
        if (snap.connectionState == ConnectionState.waiting) {
          return Center(
            child: CircularProgressIndicator(),
          );
        }
        return _NotesListView(notes: snap.data ?? []);
      },
    );
  }
}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Wire up a SupabaseStream using StreamBuilder
  2. Add/Edit a list entry
  3. Notice that the list does not update
  4. Do a hot reload
  5. Notice that the list has been updated

Expected behavior

I would expect a stream subscription to trigger an update when the associated database table has been updated.

Screenshots

Attached video demonstrates adding an entry
https://user-images.githubusercontent.com/6907797/129311348-fe88ba00-6019-4bfd-93b4-e0fac690f587.mp4

System information

  • OS: Linux/Android

Additional context

Initially discovered this issue while putting together a demo using Riverpod. I was able to work around this issue using the refresh function of Riverpod. I was also able to verify this behavior by deleting rows from the Table Editor on the Supabase Dashboard. When running in the browser, I am able to confirm that the socket connection sends back the updated entry.

Hi @chimon2000!

Thanks for opening this issue. I am struggling to reproduce this issue. If you could help me out, it would be awesome!

First, could you confirm that you have realtime turned on for your notes table?
Screen Shot 2021-08-13 at 21 17 32

If you have it turned on, could you share the schema of your notes table?

What happens if you remove the .map?

Hi @chimon2000!

Thanks for opening this issue. I am struggling to reproduce this issue. If you could help me out, it would be awesome!

First, could you confirm that you have realtime turned on for your notes table?
Screen Shot 2021-08-13 at 21 17 32

If you have it turned on, could you share the schema of your notes table?

Testing this now. I did not have this feature enabled.

@dshukertjr @bdlukaa it looks like enabling streams solved my issue. The tutorial I was using had the REST implementation so that's probably why I missed it. Thanks!!!