Skip to main content
Version: v1-dev

stream()

Notifies of data at the queried table.

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

Notes

  • stream() will emit the initial data as well as any further change on the database as Stream of List<Map<String, dynamic>> by combining Postgrest and Realtime.
  • Takes a list of primary key columns as its argument.

Examples

Listening to a specific table

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

Listening to a specific rows within a table

You can listen to individual rows using the format {table}:{col}=eq.{val} - where {col} is the column name, and {val} is the value which you want to match. This syntax is the as how you can filter data in Realtime

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

With order()

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

With limit()

supabase.from('countries')
.stream(['id'])
.order('name', ascending: true)
.limit(10)
.listen((List<Map<String, dynamic>> data) {
// Do something awesome with the data
});

Using stream() with StreamBuilder

When using stream() with a StreamBuilder within your Flutter application, make sure to store your stream in a variable to prevent refetching upon rebuilding.

final supabase = Supabase.instance.client;

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


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(['id']);


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