Flutter: Listen to database changes

Returns real-time data from your table as a Stream.

Examples

Listen to a table

supabase.from('countries')
  .stream(primaryKey: ['id'])
  .listen((List<Map<String, dynamic>> data) \{
  // Do something awesome with the data
\});

With filter, order and limit

supabase.from('countries')
  .stream(primaryKey: ['id'])
  .eq('id', 120)
  .order('name')
  .limit(10);

With an IN filter

supabase.from('countries')
  .stream(primaryKey: ['id'])
  .inFilter('id', [1, 2, 3])
  .order('name')
  .limit(10);

Using `stream()` with `StreamBuilder`

final supabase = Supabase.instance.client;

class MyWidget extends StatefulWidget \{
  const MyWidget(\{Key? key\}) : super(key: key);

  @override
  State<MyWidget> createState() => _MyWidgetState();
\}

class _MyWidgetState extends State<MyWidget> \{
  // Persist the stream in a local variable to prevent refetching upon rebuilds
  final _stream = supabase.from('countries').stream(primaryKey: ['id']);

  @override
  Widget build(BuildContext context) \{
    return StreamBuilder(
      stream: _stream,
      builder: (context, snapshot) \{
        // Return your widget with the data from the snapshot
      \},
    );
  \}
\}