Implemented per stream subscription recovery with polling fallback
This commit is contained in:
@@ -3,14 +3,28 @@ import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import '../models/user_office.dart';
|
||||
import 'supabase_provider.dart';
|
||||
import 'stream_recovery.dart';
|
||||
|
||||
final userOfficesProvider = StreamProvider<List<UserOffice>>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return client
|
||||
.from('user_offices')
|
||||
.stream(primaryKey: ['user_id', 'office_id'])
|
||||
.order('created_at')
|
||||
.map((rows) => rows.map(UserOffice.fromMap).toList());
|
||||
|
||||
final wrapper = StreamRecoveryWrapper<UserOffice>(
|
||||
stream: client
|
||||
.from('user_offices')
|
||||
.stream(primaryKey: ['user_id', 'office_id'])
|
||||
.order('created_at'),
|
||||
onPollData: () async {
|
||||
final data = await client
|
||||
.from('user_offices')
|
||||
.select()
|
||||
.order('created_at');
|
||||
return data.map(UserOffice.fromMap).toList();
|
||||
},
|
||||
fromMap: UserOffice.fromMap,
|
||||
);
|
||||
|
||||
ref.onDispose(wrapper.dispose);
|
||||
return wrapper.stream.map((result) => result.data);
|
||||
});
|
||||
|
||||
final userOfficesControllerProvider = Provider<UserOfficesController>((ref) {
|
||||
|
||||
Reference in New Issue
Block a user