Skip to content

Unexpected behavior in realtime events in Flutter android app #706

Open
@B0yma

Description

@B0yma

Bug report

  • [+] I confirm this is a bug with Supabase, not with my own application.
  • [+] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Unexpected behavior in flutter android app. in some cases realtime events on update not fired. in some cases fired with wrong data

To Reproduce

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

  1. create table with rls policy
create table
  public.test (
    id bigint generated by default as identity,
    some_int bigint null,
    constraint test_pkey primary key (id)
  ) tablespace pg_default;
  
  BEGIN;
  ALTER POLICY "Enable read access for all users" ON "public"."test" USING ((some_int >= 1));
COMMIT;
  1. put rows with some_int - [0, 1, 2]

  2. run flutter app with your secrets

Future<void> main() async {
  final supabase = await Supabase.initialize(
    url: supabaseUrl,
    anonKey: supabaseAnonKey,
  );
  runApp(MyApp(supabase: supabase));
}

class MyApp extends StatelessWidget {

  final Supabase supabase;
  const MyApp( {super.key, required this.supabase});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: StreamBuilder<List<int>>(
        stream: getSomeInts(),
        initialData: const [],
        builder: (context, snapshot) {
          return const FlutterLogo();
        }
      )
    );
  }

  Stream<List<int>> getSomeInts() {
    return supabase.client.from('test').stream(primaryKey: ['id']).map((event) {
      log("event.toString():$event");
      return event.map((e) => e['some_int'] as int).toList();
    });
  }
}

you will see in log

event.toString():[{id: 2, some_int: 1}, {id: 3, some_int: 2}]
  1. change in supbase some_int from 0 -> 3
    you will see in log
event.toString():[{id: 2, some_int: 1}, {id: 3, some_int: 2}, {id: 1, some_int: 3}]
  1. change in supbase some_int from 3 -> 0
    log not fires

Expected behavior

event fires

  1. change in supbase some_int from 1 -> 3
    you will see in log
event.toString():[{id: 2, some_int: 3}, {id: 3, some_int: 2}, {id: 1, some_int: 3}]

its wrong data

Expected behavior

correct data [0,3,2]

Screenshots

image
image

System information

  • OS: Windows 10

Additional context

flutter doctor

  • Doctor summary (to see all details, run flutter doctor -v):
  • [√] Flutter (Channel stable, 3.13.6, on Microsoft Windows [Version 10.0.19045.2251]
  • Android Studio (version 2022.3)

version of supabse in pubspec of flutter

  • supabase_flutter: ^1.10.23

device

  • android emulator api33_x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedThis issue is blocked by another issuebugSomething isn't workingrealtimeThis issue or pull request is related to realtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions