Implemented per stream subscription recovery with polling fallback
This commit is contained in:
@@ -2,14 +2,22 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../models/service.dart';
|
||||
import 'supabase_provider.dart';
|
||||
import 'stream_recovery.dart';
|
||||
|
||||
final servicesProvider = StreamProvider<List<Service>>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return client
|
||||
.from('services')
|
||||
.stream(primaryKey: ['id'])
|
||||
.order('name')
|
||||
.map((rows) => rows.map((r) => Service.fromMap(r)).toList());
|
||||
|
||||
final wrapper = StreamRecoveryWrapper<Service>(
|
||||
stream: client.from('services').stream(primaryKey: ['id']).order('name'),
|
||||
onPollData: () async {
|
||||
final data = await client.from('services').select().order('name');
|
||||
return data.map(Service.fromMap).toList();
|
||||
},
|
||||
fromMap: Service.fromMap,
|
||||
);
|
||||
|
||||
ref.onDispose(wrapper.dispose);
|
||||
return wrapper.stream.map((result) => result.data);
|
||||
});
|
||||
|
||||
final servicesOnceProvider = FutureProvider<List<Service>>((ref) async {
|
||||
|
||||
Reference in New Issue
Block a user