Returns real-time data from your table as a Stream.
stream() will emit the initial data as well as any further change on the database as Stream<List<Map<String, dynamic>>> by combining Postgrest and Realtime.channelOptions: const RealtimeChannelConfig(private: true) to the stream() call..eq('column', value) listens to rows where the column equals the value.neq('column', value) listens to rows where the column does not equal the value.gt('column', value) listens to rows where the column is greater than the value.gte('column', value) listens to rows where the column is greater than or equal to the value.lt('column', value) listens to rows where the column is less than the value.lte('column', value) listens to rows where the column is less than or equal to the value.inFilter('column', [val1, val2, val3]) listens to rows where the column is one of the values.like('column', pattern) listens to rows where the column matches the given LIKE pattern.ilike('column', pattern) listens to rows where the column matches the given case-insensitive LIKE pattern.matchRegex('column', pattern) listens to rows where the column matches the given PostgreSQL regular expression, case-sensitive.imatchRegex('column', pattern) listens to rows where the column matches the given PostgreSQL regular expression, case-insensitive.isFilter('column', value) listens to rows where the column IS the given value (e.g. null, true, false).isDistinct('column', value) listens to rows where the column IS DISTINCT FROM the given valuestream() call, and they are combined with AND both when fetching the initial data and when filtering realtime changes.UPDATE events, a filter such as .eq() is only re-evaluated against the new row. If a row stops matching the filter after an update, it is not removed from the stream and will remain in its last known state until it is deleted or the stream is restarted.DELETE events only include the primary key columns of the deleted row by default, not the full previous row.supabase.from('countries')
.stream(primaryKey: ['id'])
.listen((List<Map<String, dynamic>> data) {
// Do something awesome with the data
});
supabase.from('countries')
.stream(primaryKey: ['id'])
.eq('id', 120)
.order('name')
.limit(10);
supabase.from('countries')
.stream(primaryKey: ['id'])
.inFilter('id', [1, 2, 3])
.order('name')
.limit(10);
supabase.from('countries')
.stream(primaryKey: ['id'])
.eq('continent', 'Asia')
.like('name', '%Republic%')
.order('name')
.limit(10);
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
},
);
}
}