Flutter Developer
Hello Appwrite community! I have a "chores" app. When User A adds a chore to a shared list, I want it to appear instantly on User B's screen without them needing to refresh.
Real-time updates are not being received by other users. However, if I manually refresh the screen, the new chore appears correctly, which proves that the basic database read permissions are working.
If I set the chores collection's read permission to Any or Guests, the real-time updates work perfectly. As soon as I restrict it to authenticated users (Users), the real-time events stop, even though the users are logged in and can fetch the data when refreshing.
I'm trying to follow the simple pattern used in many working chat apps.
- Flutter Client (chore_state_notifier.dart) - Subscribing
My Flutter app subscribes directly to the chores collection.
`// lib/features/chores/presentation/providers/chore_state_notifier.dart
void _subscribeToChoreUpdates() {
final realtime = _ref.read(appwriteRealtimeProvider);
final databaseId = AppwriteConstants.databaseId;
final collectionId = AppwriteConstants.choresCollectionId;
// Subscribing directly to the chores collection
final channel = 'databases.$databaseId.collections.$collectionId.documents';
_subscription = realtime.subscribe([channel]);
_subscription!.stream.listen((response) {
**// THIS PRINT STATEMENT NEVER APPEARS FOR OTHER USERS**
print("<<<<< DIRECT REALTIME EVENT RECEIVED: ${response.payload} >>>>>");
// ... logic to update the UI state
});
}`
Logs:
I/flutter (20357): Received heartbeat response from realtime server I/flutter (20357): subscription: wss://fra.cloud.appwrite.io/v1/realtime?project=xxxx&channels%5B%5D=databases.xxxx.collections.chores.documents I/flutter (20357): subscription: wss://fra.cloud.appwrite.io/v1/realtime?project=xxxx&channels%5B%5D=databases.xxxx.collections.chores.documents&channels%5B%5D=databases.xxxx.collections.choreLists.documents