This commit is contained in:
2025-10-26 17:53:53 +01:00
parent 348746c0d4
commit 8c1de0f883
8 changed files with 922 additions and 843 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:pocketbase/pocketbase.dart';
import 'package:shoppinglist/models/models.dart';
@@ -31,6 +33,28 @@ class ApiService {
pb.authStore.clear();
}
Stream<void> watchLists() {
if (userId == null) return Stream.value(null);
late final StreamController<void> controller;
Future<void> Function()? unsubscribe;
controller = StreamController<void>(
onListen: () async {
unsubscribe = await pb.collection('lists').subscribe('*', (e) {
if (!controller.isClosed) {
controller.add(null);
}
}, filter: 'owner = "$userId" || members ?~ "$userId"');
},
onCancel: () {
unsubscribe?.call();
},
);
return controller.stream;
}
Future<List<Liste>> getLists() async {
if (userId == null) return [];
final List<RecordModel> res = await pb
@@ -67,6 +91,26 @@ class ApiService {
await pb.collection('lists').delete(listId);
}
Stream<void> watchItems(String listId) {
late final StreamController<void> controller;
Future<void> Function()? unsubscribe;
controller = StreamController<void>(
onListen: () async {
unsubscribe = await pb.collection('items').subscribe('*', (e) {
if (!controller.isClosed) {
controller.add(null);
}
}, filter: 'list = "$listId"');
},
onCancel: () {
unsubscribe?.call();
},
);
return controller.stream;
}
Future<List<Item>> getItems(String listId) async {
final List<RecordModel> res = await pb
.collection('items')